
cvsubs74/mcp
Developer tools이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요. 원문 보기
이 가이드는 구현, 테스트 및 MCP (모델 Context Protocol) 서버 및 FastMCP를 사용하여 일치하는 클라이언트를 배포하는 실용적인 디자인 패턴을 개요합니다.
개요
이 가이드는 구현, 테스트 및 MCP (모델 Context Protocol) 서버 및 FastMCP를 사용하여 일치하는 클라이언트를 배포하는 실용적인 디자인 패턴을 개요합니다. 그것은 프레임 워크- 및 클라우드-agnostic는 콘크리트 예제와 도움이. You will learn: - 권장된 프로젝트 레이아웃 - 핵심 의존성 및 환경 설정 - 서버 디자인 패턴 (툴, 수송, 일련화) - 클라이언트 디자인 패턴 (연결, 목록, 전화) - 테스트 패턴 (메모리 단위 테스트 및 HTTP 통합 테스트) - 컨테이너화 및 배포 옵션 - server.py - FastMCP 서버, 도구 및 HTTP 전송 시작 - client.py - Minimal FastMCP 클라이언트 예제 - test mcp inmemory.py - In‐memory, pytest-based unit tests that import the server directly - test mcp server.py - 배포 된 HTTP 서버에 대한 단순화 된 통합 테스트 - Dockerfile - Cloud Run을위한 컨테이너 빌드 - pyproject.toml - Python 프로젝트 및 의존성 메타 데이터 -.
개요(AI 번역)
이 가이드는 구현, 테스트 및 MCP (모델 Context Protocol) 서버 및 FastMCP를 사용하여 일치하는 클라이언트를 배포하는 실용적인 디자인 패턴을 개요합니다. 그것은 프레임 워크- 및 클라우드-agnostic는 콘크리트 예제와 도움이.
당신은 배울 것이다:
- 권장 프로젝트 레이아웃
- 핵심 의존성 및 환경 설정
- 서버 디자인 패턴 (툴, 수송, 일련화)
- 클라이언트 디자인 패턴 (connect, list, call)
- 테스트 패턴 (메모리 단위 테스트 및 HTTP 통합 테스트)
- 컨테이너화 및 배포 옵션
추천 프로젝트 구조
server.py- FastMCP 서버, 도구 및 HTTP 전송 시작client.py- Minimal FastMCP 클라이언트 예test_mcp_inmemory.py— In-memory, 서버를 직접 가져올 pytest 기반 단위 테스트test_mcp_server.py- 배포된 HTTP 서버에 대한 단순 통합 테스트Dockerfile- Cloud Run용 컨테이너 구축pyproject.toml- Python 프로젝트 및 의존성 메타데이터requirements.txt- 도커 이미지의 Pinned runtime Dependencies
서버 디자인 패턴
단일 FastMCP 인스턴스를 내보내는 모듈로 서버를 구현하고 MCP 도구로 Python 기능을 장식합니다.
이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요.
README
원문 README의 일부입니다. 원문 보기.
Building an MCP Server and Client
This guide outlines a practical design pattern to implement, test, and deploy an MCP (Model Context Protocol) server and a matching client using FastMCP. It is framework- and cloud-agnostic with concrete examples where helpful.
You will learn:
- The recommended project layout
- Core dependencies and environment setup
- Server design patterns (tools, transports, serialization)
- Client design patterns (connect, list, call)
- Testing patterns (in-memory unit tests and HTTP integration tests)
- Containerization and deployment options
Recommended Project Structure
server.py— FastMCP server, tools, and HTTP transport startupclient.py— Minimal FastMCP client exampletest_mcp_inmemory.py— In‑memory, pytest-based unit tests that import the server directlytest_mcp_server.py— Simplified integration tests against the deployed HTTP serverDockerfile— Container build for Cloud Runpyproject.toml— Python project and dependency metadatarequirements.txt— Pinned runtime dependencies for Docker image
Server Design Pattern
Implement the server as a module that exports a single FastMCP instance and decorates Python functions as MCP tools. Keep business logic pure and testable, and return JSON-serializable results.
Core pattern:
from typing import Any, Dict, List
from fastmcp import FastMCP
mcp = FastMCP("Your MCP Server Name")
@mcp.tool()
def your_tool(arg1: str, limit: int = 10) -> List[Dict[str, Any]]:
"""Describe what this tool does in one sentence."""
# Validate inputs (FastMCP also validates based on type hints)
# Query/compute your results
return [{"ok": True, "arg1": arg1, "limit": limit}]
Transports:
- In-memory: ideal for testing via
Client(mcp) - HTTP (streamable): ideal for remote consumption by HTTP clients
- Other transports: depending on FastMCP support and your needs
HTTP startup:
# server.py
import asyncio, os
if __name__ == "__main__":
asyncio.run(
mcp.run_async(
transport="streamable-http",
host="0.0.0.0",
port=os.getenv("PORT", 8080),
)
)
Notes:
- Prefer explicit, typed function signatures. FastMCP generates JSON Schema automatically.
- Ensure all return values are JSON-serializable (dict, list, str, int, float, bool, None).
- If you expose HTTP, document the base path (e.g.,
/mcp/) and any auth requirements.
Client Design Pattern
Use the asynchronous context manager to connect, list tools, and call tools. When testing in-memory, pass the server instance directly; when testing remotely, pass the server URL.
Basic patterns:
from fastmcp import Client
# Remote HTTP client
async def main_remote():
async with Client("https://your-server.example.com/mcp/") as client:
await client.ping()
tools = await client.list_tools()
result = await client.call_tool("your_tool", {"arg1": "value", "limit": 5})
설치
This server does not publish a one-line install command.
Open the repository installation guide MCP 초보자라면? mcpskill.org 가이드부터 시작하세요 →