Rename FastMCP to MCPServer (#1951)
This commit is contained in:
parent
4a2d83a0cb
commit
65c614e48e
24 changed files with 713 additions and 693 deletions
|
|
@ -12,7 +12,7 @@ from mcp.shared.metadata_utils import get_display_name
|
|||
# Create server parameters for stdio connection
|
||||
server_params = StdioServerParameters(
|
||||
command="uv", # Using uv to run the server
|
||||
args=["run", "server", "fastmcp_quickstart", "stdio"],
|
||||
args=["run", "server", "mcpserver_quickstart", "stdio"],
|
||||
env={"UV_INDEX": os.environ.get("UV_INDEX", "")},
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from mcp.shared.context import RequestContext
|
|||
# Create server parameters for stdio connection
|
||||
server_params = StdioServerParameters(
|
||||
command="uv", # Using uv to run the server
|
||||
args=["run", "server", "fastmcp_quickstart", "stdio"], # We're already in snippets dir
|
||||
args=["run", "server", "mcpserver_quickstart", "stdio"], # We're already in snippets dir
|
||||
env={"UV_INDEX": os.environ.get("UV_INDEX", "")},
|
||||
)
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ async def run():
|
|||
prompts = await session.list_prompts()
|
||||
print(f"Available prompts: {[p.name for p in prompts.prompts]}")
|
||||
|
||||
# Get a prompt (greet_user prompt from fastmcp_quickstart)
|
||||
# Get a prompt (greet_user prompt from mcpserver_quickstart)
|
||||
if prompts.prompts:
|
||||
prompt = await session.get_prompt("greet_user", arguments={"name": "Alice", "style": "friendly"})
|
||||
print(f"Prompt result: {prompt.messages[0].content}")
|
||||
|
|
@ -56,13 +56,13 @@ async def run():
|
|||
tools = await session.list_tools()
|
||||
print(f"Available tools: {[t.name for t in tools.tools]}")
|
||||
|
||||
# Read a resource (greeting resource from fastmcp_quickstart)
|
||||
# Read a resource (greeting resource from mcpserver_quickstart)
|
||||
resource_content = await session.read_resource("greeting://World")
|
||||
content_block = resource_content.contents[0]
|
||||
if isinstance(content_block, types.TextContent):
|
||||
print(f"Resource content: {content_block.text}")
|
||||
|
||||
# Call a tool (add tool from fastmcp_quickstart)
|
||||
# Call a tool (add tool from mcpserver_quickstart)
|
||||
result = await session.call_tool("add", arguments={"a": 5, "b": 3})
|
||||
result_unstructured = result.content[0]
|
||||
if isinstance(result_unstructured, types.TextContent):
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue