Rename FastMCP to MCPServer (#1951)
This commit is contained in:
parent
4a2d83a0cb
commit
65c614e48e
22 changed files with 713 additions and 693 deletions
|
|
@ -22,7 +22,7 @@ def run_server():
|
|||
print("Usage: server <server-name> [transport]")
|
||||
print("Available servers: basic_tool, basic_resource, basic_prompt, tool_progress,")
|
||||
print(" sampling, elicitation, completion, notifications,")
|
||||
print(" fastmcp_quickstart, structured_output, images")
|
||||
print(" mcpserver_quickstart, structured_output, images")
|
||||
print("Available transports: stdio (default), sse, streamable-http")
|
||||
sys.exit(1)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from mcp.server.fastmcp import FastMCP
|
||||
from mcp.server.fastmcp.prompts import base
|
||||
from mcp.server.mcpserver import MCPServer
|
||||
from mcp.server.mcpserver.prompts import base
|
||||
|
||||
mcp = FastMCP(name="Prompt Example")
|
||||
mcp = MCPServer(name="Prompt Example")
|
||||
|
||||
|
||||
@mcp.prompt(title="Code Review")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from mcp.server.fastmcp import FastMCP
|
||||
from mcp.server.mcpserver import MCPServer
|
||||
|
||||
mcp = FastMCP(name="Resource Example")
|
||||
mcp = MCPServer(name="Resource Example")
|
||||
|
||||
|
||||
@mcp.resource("file://documents/{name}")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from mcp.server.fastmcp import FastMCP
|
||||
from mcp.server.mcpserver import MCPServer
|
||||
|
||||
mcp = FastMCP(name="Tool Example")
|
||||
mcp = MCPServer(name="Tool Example")
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from mcp.server.fastmcp import FastMCP
|
||||
from mcp.server.mcpserver import MCPServer
|
||||
from mcp.types import (
|
||||
Completion,
|
||||
CompletionArgument,
|
||||
|
|
@ -7,7 +7,7 @@ from mcp.types import (
|
|||
ResourceTemplateReference,
|
||||
)
|
||||
|
||||
mcp = FastMCP(name="Example")
|
||||
mcp = MCPServer(name="Example")
|
||||
|
||||
|
||||
@mcp.resource("github://repos/{owner}/{repo}")
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ from typing import Annotated
|
|||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
from mcp.server.mcpserver import MCPServer
|
||||
from mcp.types import CallToolResult, TextContent
|
||||
|
||||
mcp = FastMCP("CallToolResult Example")
|
||||
mcp = MCPServer("CallToolResult Example")
|
||||
|
||||
|
||||
class ValidationModel(BaseModel):
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ cd to the `examples/snippets` directory and run:
|
|||
python servers/direct_execution.py
|
||||
"""
|
||||
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
from mcp.server.mcpserver import MCPServer
|
||||
|
||||
mcp = FastMCP("My App")
|
||||
mcp = MCPServer("My App")
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ import uuid
|
|||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from mcp.server.fastmcp import Context, FastMCP
|
||||
from mcp.server.mcpserver import Context, MCPServer
|
||||
from mcp.server.session import ServerSession
|
||||
from mcp.shared.exceptions import UrlElicitationRequiredError
|
||||
from mcp.types import ElicitRequestURLParams
|
||||
|
||||
mcp = FastMCP(name="Elicitation Example")
|
||||
mcp = MCPServer(name="Elicitation Example")
|
||||
|
||||
|
||||
class BookingPreferences(BaseModel):
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
"""Example showing image handling with FastMCP."""
|
||||
"""Example showing image handling with MCPServer."""
|
||||
|
||||
from PIL import Image as PILImage
|
||||
|
||||
from mcp.server.fastmcp import FastMCP, Image
|
||||
from mcp.server.mcpserver import Image, MCPServer
|
||||
|
||||
mcp = FastMCP("Image Example")
|
||||
mcp = MCPServer("Image Example")
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from collections.abc import AsyncIterator
|
|||
from contextlib import asynccontextmanager
|
||||
from dataclasses import dataclass
|
||||
|
||||
from mcp.server.fastmcp import Context, FastMCP
|
||||
from mcp.server.mcpserver import Context, MCPServer
|
||||
from mcp.server.session import ServerSession
|
||||
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ class AppContext:
|
|||
|
||||
|
||||
@asynccontextmanager
|
||||
async def app_lifespan(server: FastMCP) -> AsyncIterator[AppContext]:
|
||||
async def app_lifespan(server: MCPServer) -> AsyncIterator[AppContext]:
|
||||
"""Manage application lifecycle with type-safe context."""
|
||||
# Initialize on startup
|
||||
db = await Database.connect()
|
||||
|
|
@ -46,7 +46,7 @@ async def app_lifespan(server: FastMCP) -> AsyncIterator[AppContext]:
|
|||
|
||||
|
||||
# Pass lifespan to server
|
||||
mcp = FastMCP("My App", lifespan=app_lifespan)
|
||||
mcp = MCPServer("My App", lifespan=app_lifespan)
|
||||
|
||||
|
||||
# Access type-safe lifespan context in tools
|
||||
|
|
|
|||
42
examples/snippets/servers/mcpserver_quickstart.py
Normal file
42
examples/snippets/servers/mcpserver_quickstart.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
"""MCPServer quickstart example.
|
||||
|
||||
Run from the repository root:
|
||||
uv run examples/snippets/servers/mcpserver_quickstart.py
|
||||
"""
|
||||
|
||||
from mcp.server.mcpserver import MCPServer
|
||||
|
||||
# Create an MCP server
|
||||
mcp = MCPServer("Demo")
|
||||
|
||||
|
||||
# Add an addition tool
|
||||
@mcp.tool()
|
||||
def add(a: int, b: int) -> int:
|
||||
"""Add two numbers"""
|
||||
return a + b
|
||||
|
||||
|
||||
# Add a dynamic greeting resource
|
||||
@mcp.resource("greeting://{name}")
|
||||
def get_greeting(name: str) -> str:
|
||||
"""Get a personalized greeting"""
|
||||
return f"Hello, {name}!"
|
||||
|
||||
|
||||
# Add a prompt
|
||||
@mcp.prompt()
|
||||
def greet_user(name: str, style: str = "friendly") -> str:
|
||||
"""Generate a greeting prompt"""
|
||||
styles = {
|
||||
"friendly": "Please write a warm, friendly greeting",
|
||||
"formal": "Please write a formal, professional greeting",
|
||||
"casual": "Please write a casual, relaxed greeting",
|
||||
}
|
||||
|
||||
return f"{styles.get(style, styles['friendly'])} for someone named {name}."
|
||||
|
||||
|
||||
# Run with streamable HTTP transport
|
||||
if __name__ == "__main__":
|
||||
mcp.run(transport="streamable-http", json_response=True)
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
from mcp.server.fastmcp import Context, FastMCP
|
||||
from mcp.server.mcpserver import Context, MCPServer
|
||||
from mcp.server.session import ServerSession
|
||||
|
||||
mcp = FastMCP(name="Notifications Example")
|
||||
mcp = MCPServer(name="Notifications Example")
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from pydantic import AnyHttpUrl
|
|||
|
||||
from mcp.server.auth.provider import AccessToken, TokenVerifier
|
||||
from mcp.server.auth.settings import AuthSettings
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
from mcp.server.mcpserver import MCPServer
|
||||
|
||||
|
||||
class SimpleTokenVerifier(TokenVerifier):
|
||||
|
|
@ -16,8 +16,8 @@ class SimpleTokenVerifier(TokenVerifier):
|
|||
pass # This is where you would implement actual token validation
|
||||
|
||||
|
||||
# Create FastMCP instance as a Resource Server
|
||||
mcp = FastMCP(
|
||||
# Create MCPServer instance as a Resource Server
|
||||
mcp = MCPServer(
|
||||
"Weather Service",
|
||||
# Token verifier for authentication
|
||||
token_verifier=SimpleTokenVerifier(),
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
from mcp.server.fastmcp import Context, FastMCP
|
||||
from mcp.server.mcpserver import Context, MCPServer
|
||||
from mcp.server.session import ServerSession
|
||||
from mcp.types import SamplingMessage, TextContent
|
||||
|
||||
mcp = FastMCP(name="Sampling Example")
|
||||
mcp = MCPServer(name="Sampling Example")
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
uv run examples/snippets/servers/streamable_config.py
|
||||
"""
|
||||
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
from mcp.server.mcpserver import MCPServer
|
||||
|
||||
mcp = FastMCP("StatelessServer")
|
||||
mcp = MCPServer("StatelessServer")
|
||||
|
||||
|
||||
# Add a simple tool to demonstrate the server
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ import contextlib
|
|||
from starlette.applications import Starlette
|
||||
from starlette.routing import Mount
|
||||
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
from mcp.server.mcpserver import MCPServer
|
||||
|
||||
# Create MCP server
|
||||
mcp = FastMCP("My App")
|
||||
mcp = MCPServer("My App")
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ import contextlib
|
|||
from starlette.applications import Starlette
|
||||
from starlette.routing import Host
|
||||
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
from mcp.server.mcpserver import MCPServer
|
||||
|
||||
# Create MCP server
|
||||
mcp = FastMCP("MCP Host App")
|
||||
mcp = MCPServer("MCP Host App")
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ import contextlib
|
|||
from starlette.applications import Starlette
|
||||
from starlette.routing import Mount
|
||||
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
from mcp.server.mcpserver import MCPServer
|
||||
|
||||
# Create multiple MCP servers
|
||||
api_mcp = FastMCP("API Server")
|
||||
chat_mcp = FastMCP("Chat Server")
|
||||
api_mcp = MCPServer("API Server")
|
||||
chat_mcp = MCPServer("Chat Server")
|
||||
|
||||
|
||||
@api_mcp.tool()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
"""Example showing path configuration when mounting FastMCP.
|
||||
"""Example showing path configuration when mounting MCPServer.
|
||||
|
||||
Run from the repository root:
|
||||
uvicorn examples.snippets.servers.streamable_http_path_config:app --reload
|
||||
|
|
@ -7,10 +7,10 @@ Run from the repository root:
|
|||
from starlette.applications import Starlette
|
||||
from starlette.routing import Mount
|
||||
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
from mcp.server.mcpserver import MCPServer
|
||||
|
||||
# Create a simple FastMCP server
|
||||
mcp_at_root = FastMCP("My Server")
|
||||
# Create a simple MCPServer server
|
||||
mcp_at_root = MCPServer("My Server")
|
||||
|
||||
|
||||
@mcp_at_root.tool()
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ import contextlib
|
|||
from starlette.applications import Starlette
|
||||
from starlette.routing import Mount
|
||||
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
from mcp.server.mcpserver import MCPServer
|
||||
|
||||
# Create the Echo server
|
||||
echo_mcp = FastMCP(name="EchoServer")
|
||||
echo_mcp = MCPServer(name="EchoServer")
|
||||
|
||||
|
||||
@echo_mcp.tool()
|
||||
|
|
@ -20,7 +20,7 @@ def echo(message: str) -> str:
|
|||
|
||||
|
||||
# Create the Math server
|
||||
math_mcp = FastMCP(name="MathServer")
|
||||
math_mcp = MCPServer(name="MathServer")
|
||||
|
||||
|
||||
@math_mcp.tool()
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue