style: Fix imports and line length formatting
This commit is contained in:
parent
7bbf71e29a
commit
a79f51f55f
37 changed files with 232 additions and 125 deletions
|
|
@ -4,8 +4,10 @@ FastMCP Complex inputs Example
|
||||||
Demonstrates validation via pydantic with complex models.
|
Demonstrates validation via pydantic with complex models.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
|
||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
|
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
from mcp.server.fastmcp import FastMCP
|
from mcp.server.fastmcp import FastMCP
|
||||||
|
|
||||||
mcp = FastMCP("Shrimp Tank")
|
mcp = FastMCP("Shrimp Tank")
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Recursive memory system inspired by the human brain's clustering of memories.
|
Recursive memory system inspired by the human brain's clustering of memories.
|
||||||
Uses OpenAI's 'text-embedding-3-small' model and pgvector for efficient similarity search.
|
Uses OpenAI's 'text-embedding-3-small' model and pgvector for efficient
|
||||||
|
similarity search.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
@ -111,7 +112,8 @@ class MemoryNode(BaseModel):
|
||||||
if self.id is None:
|
if self.id is None:
|
||||||
result = await conn.fetchrow(
|
result = await conn.fetchrow(
|
||||||
"""
|
"""
|
||||||
INSERT INTO memories (content, summary, importance, access_count, timestamp, embedding)
|
INSERT INTO memories (content, summary, importance, access_count,
|
||||||
|
timestamp, embedding)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6)
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
""",
|
""",
|
||||||
|
|
@ -336,7 +338,8 @@ async def initialize_database():
|
||||||
timestamp DOUBLE PRECISION NOT NULL,
|
timestamp DOUBLE PRECISION NOT NULL,
|
||||||
embedding vector(1536) NOT NULL
|
embedding vector(1536) NOT NULL
|
||||||
);
|
);
|
||||||
CREATE INDEX IF NOT EXISTS idx_memories_embedding ON memories USING hnsw (embedding vector_l2_ops);
|
CREATE INDEX IF NOT EXISTS idx_memories_embedding ON memories
|
||||||
|
USING hnsw (embedding vector_l2_ops);
|
||||||
""")
|
""")
|
||||||
finally:
|
finally:
|
||||||
await pool.close()
|
await pool.close()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
from mcp.server.fastmcp import FastMCP
|
from mcp.server.fastmcp import FastMCP
|
||||||
|
|
||||||
|
|
||||||
# Create an MCP server
|
# Create an MCP server
|
||||||
mcp = FastMCP("Demo")
|
mcp = FastMCP("Demo")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ Give Claude a tool to capture and view screenshots.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import io
|
import io
|
||||||
|
|
||||||
from mcp.server.fastmcp import FastMCP
|
from mcp.server.fastmcp import FastMCP
|
||||||
from mcp.server.fastmcp.utilities.types import Image
|
from mcp.server.fastmcp.utilities.types import Image
|
||||||
|
|
||||||
|
|
||||||
# Create server
|
# Create server
|
||||||
mcp = FastMCP("Screenshot Demo", dependencies=["pyautogui", "Pillow"])
|
mcp = FastMCP("Screenshot Demo", dependencies=["pyautogui", "Pillow"])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ FastMCP Echo Server
|
||||||
|
|
||||||
from mcp.server.fastmcp import FastMCP
|
from mcp.server.fastmcp import FastMCP
|
||||||
|
|
||||||
|
|
||||||
# Create server
|
# Create server
|
||||||
mcp = FastMCP("Echo Server")
|
mcp = FastMCP("Echo Server")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ Visit https://surgemsg.com/ and click "Get Started" to obtain these values.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from pydantic import BeforeValidator
|
from pydantic import BeforeValidator
|
||||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import anyio
|
import anyio
|
||||||
import click
|
import click
|
||||||
import mcp.types as types
|
import mcp.types as types
|
||||||
from pydantic import AnyUrl
|
|
||||||
from mcp.server.lowlevel import Server
|
from mcp.server.lowlevel import Server
|
||||||
|
from pydantic import AnyUrl
|
||||||
|
|
||||||
SAMPLE_RESOURCES = {
|
SAMPLE_RESOURCES = {
|
||||||
"greeting": "Hello! This is a sample text resource.",
|
"greeting": "Hello! This is a sample text resource.",
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,6 @@ dev-dependencies = [
|
||||||
"trio>=0.26.2",
|
"trio>=0.26.2",
|
||||||
"pytest-flakefinder>=1.1.0",
|
"pytest-flakefinder>=1.1.0",
|
||||||
"pytest-xdist>=3.6.1",
|
"pytest-xdist>=3.6.1",
|
||||||
"pytest-asyncio>=0.24.0",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,5 @@
|
||||||
|
|
||||||
from .cli import app
|
from .cli import app
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app()
|
app()
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,8 @@ def update_claude_config(
|
||||||
config_dir = get_claude_config_path()
|
config_dir = get_claude_config_path()
|
||||||
if not config_dir:
|
if not config_dir:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"Claude Desktop config directory not found. Please ensure Claude Desktop "
|
"Claude Desktop config directory not found. Please ensure Claude Desktop"
|
||||||
"is installed and has been run at least once to initialize its configuration."
|
" is installed and has been run at least once to initialize its config."
|
||||||
)
|
)
|
||||||
|
|
||||||
config_file = config_dir / "claude_desktop_config.json"
|
config_file = config_dir / "claude_desktop_config.json"
|
||||||
|
|
|
||||||
|
|
@ -295,7 +295,8 @@ def run(
|
||||||
"""Run a MCP server.
|
"""Run a MCP server.
|
||||||
|
|
||||||
The server can be specified in two ways:
|
The server can be specified in two ways:
|
||||||
1. Module approach: server.py - runs the module directly, expecting a server.run() call
|
1. Module approach: server.py - runs the module directly, expecting a server.run()
|
||||||
|
call
|
||||||
2. Import approach: server.py:app - imports and runs the specified server object
|
2. Import approach: server.py:app - imports and runs the specified server object
|
||||||
|
|
||||||
Note: This command runs the server directly. You are responsible for ensuring
|
Note: This command runs the server directly. You are responsible for ensuring
|
||||||
|
|
@ -346,7 +347,8 @@ def install(
|
||||||
typer.Option(
|
typer.Option(
|
||||||
"--name",
|
"--name",
|
||||||
"-n",
|
"-n",
|
||||||
help="Custom name for the server (defaults to server's name attribute or file name)",
|
help="Custom name for the server (defaults to server's name attribute or"
|
||||||
|
" file name)",
|
||||||
),
|
),
|
||||||
] = None,
|
] = None,
|
||||||
with_editable: Annotated[
|
with_editable: Annotated[
|
||||||
|
|
@ -410,7 +412,8 @@ def install(
|
||||||
logger.error("Claude app not found")
|
logger.error("Claude app not found")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Try to import server to get its name, but fall back to file name if dependencies missing
|
# Try to import server to get its name, but fall back to file name if dependencies
|
||||||
|
# missing
|
||||||
name = server_name
|
name = server_name
|
||||||
server = None
|
server = None
|
||||||
if not name:
|
if not name:
|
||||||
|
|
@ -419,7 +422,8 @@ def install(
|
||||||
name = server.name
|
name = server.name
|
||||||
except (ImportError, ModuleNotFoundError) as e:
|
except (ImportError, ModuleNotFoundError) as e:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Could not import server (likely missing dependencies), using file name",
|
"Could not import server (likely missing dependencies), using file"
|
||||||
|
" name",
|
||||||
extra={"error": str(e)},
|
extra={"error": str(e)},
|
||||||
)
|
)
|
||||||
name = file.stem
|
name = file.stem
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from .lowlevel import Server, NotificationOptions
|
|
||||||
from .fastmcp import FastMCP
|
from .fastmcp import FastMCP
|
||||||
|
from .lowlevel import NotificationOptions, Server
|
||||||
|
|
||||||
__all__ = ["Server", "FastMCP", "NotificationOptions"]
|
__all__ = ["Server", "FastMCP", "NotificationOptions"]
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
"""FastMCP - A more ergonomic interface for MCP servers."""
|
"""FastMCP - A more ergonomic interface for MCP servers."""
|
||||||
|
|
||||||
from importlib.metadata import version
|
from importlib.metadata import version
|
||||||
from .server import FastMCP, Context
|
|
||||||
|
from .server import Context, FastMCP
|
||||||
from .utilities.types import Image
|
from .utilities.types import Image
|
||||||
|
|
||||||
__version__ = version("mcp")
|
__version__ = version("mcp")
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
"""Base classes for FastMCP prompts."""
|
"""Base classes for FastMCP prompts."""
|
||||||
|
|
||||||
import json
|
|
||||||
from typing import Any, Literal, Sequence, Awaitable
|
|
||||||
import inspect
|
import inspect
|
||||||
|
import json
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
|
from typing import Any, Awaitable, Literal, Sequence
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, TypeAdapter, validate_call
|
|
||||||
from mcp.types import TextContent, ImageContent, EmbeddedResource
|
|
||||||
import pydantic_core
|
import pydantic_core
|
||||||
|
from pydantic import BaseModel, Field, TypeAdapter, validate_call
|
||||||
|
|
||||||
|
from mcp.types import EmbeddedResource, ImageContent, TextContent
|
||||||
|
|
||||||
CONTENT_TYPES = TextContent | ImageContent | EmbeddedResource
|
CONTENT_TYPES = TextContent | ImageContent | EmbeddedResource
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
from .base import Resource
|
from .base import Resource
|
||||||
from .types import (
|
|
||||||
TextResource,
|
|
||||||
BinaryResource,
|
|
||||||
FunctionResource,
|
|
||||||
FileResource,
|
|
||||||
HttpResource,
|
|
||||||
DirectoryResource,
|
|
||||||
)
|
|
||||||
from .templates import ResourceTemplate
|
|
||||||
from .resource_manager import ResourceManager
|
from .resource_manager import ResourceManager
|
||||||
|
from .templates import ResourceTemplate
|
||||||
|
from .types import (
|
||||||
|
BinaryResource,
|
||||||
|
DirectoryResource,
|
||||||
|
FileResource,
|
||||||
|
FunctionResource,
|
||||||
|
HttpResource,
|
||||||
|
TextResource,
|
||||||
|
)
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Resource",
|
"Resource",
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
"""Resource manager functionality."""
|
"""Resource manager functionality."""
|
||||||
|
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
from collections.abc import Iterable
|
|
||||||
|
|
||||||
from pydantic import AnyUrl
|
from pydantic import AnyUrl
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
"""Concrete resource implementations."""
|
"""Concrete resource implementations."""
|
||||||
|
|
||||||
import anyio
|
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
|
||||||
from typing import Any, Callable
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
import anyio
|
||||||
import httpx
|
import httpx
|
||||||
import pydantic.json
|
import pydantic.json
|
||||||
import pydantic_core
|
import pydantic_core
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,25 @@
|
||||||
"""FastMCP - A more ergonomic interface for MCP servers."""
|
"""FastMCP - A more ergonomic interface for MCP servers."""
|
||||||
|
|
||||||
import anyio
|
|
||||||
import functools
|
import functools
|
||||||
import inspect
|
import inspect
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from typing import Any, Callable, Literal, Sequence
|
from typing import Any, Callable, Literal, Sequence
|
||||||
from collections.abc import Iterable
|
|
||||||
|
|
||||||
|
import anyio
|
||||||
import pydantic_core
|
import pydantic_core
|
||||||
from pydantic import Field
|
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
from pydantic.networks import AnyUrl
|
||||||
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||||
|
|
||||||
|
from mcp.server.fastmcp.exceptions import ResourceError
|
||||||
|
from mcp.server.fastmcp.prompts import Prompt, PromptManager
|
||||||
|
from mcp.server.fastmcp.resources import FunctionResource, Resource, ResourceManager
|
||||||
|
from mcp.server.fastmcp.tools import ToolManager
|
||||||
|
from mcp.server.fastmcp.utilities.logging import configure_logging, get_logger
|
||||||
|
from mcp.server.fastmcp.utilities.types import Image
|
||||||
from mcp.server.lowlevel import Server as MCPServer
|
from mcp.server.lowlevel import Server as MCPServer
|
||||||
from mcp.server.sse import SseServerTransport
|
from mcp.server.sse import SseServerTransport
|
||||||
from mcp.server.stdio import stdio_server
|
from mcp.server.stdio import stdio_server
|
||||||
|
|
@ -24,6 +32,8 @@ from mcp.types import (
|
||||||
)
|
)
|
||||||
from mcp.types import (
|
from mcp.types import (
|
||||||
Prompt as MCPPrompt,
|
Prompt as MCPPrompt,
|
||||||
|
)
|
||||||
|
from mcp.types import (
|
||||||
PromptArgument as MCPPromptArgument,
|
PromptArgument as MCPPromptArgument,
|
||||||
)
|
)
|
||||||
from mcp.types import (
|
from mcp.types import (
|
||||||
|
|
@ -35,16 +45,6 @@ from mcp.types import (
|
||||||
from mcp.types import (
|
from mcp.types import (
|
||||||
Tool as MCPTool,
|
Tool as MCPTool,
|
||||||
)
|
)
|
||||||
from pydantic import BaseModel
|
|
||||||
from pydantic.networks import AnyUrl
|
|
||||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
||||||
|
|
||||||
from mcp.server.fastmcp.exceptions import ResourceError
|
|
||||||
from mcp.server.fastmcp.prompts import Prompt, PromptManager
|
|
||||||
from mcp.server.fastmcp.resources import FunctionResource, Resource, ResourceManager
|
|
||||||
from mcp.server.fastmcp.tools import ToolManager
|
|
||||||
from mcp.server.fastmcp.utilities.logging import configure_logging, get_logger
|
|
||||||
from mcp.server.fastmcp.utilities.types import Image
|
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
@ -226,8 +226,9 @@ class FastMCP:
|
||||||
def tool(self, name: str | None = None, description: str | None = None) -> Callable:
|
def tool(self, name: str | None = None, description: str | None = None) -> Callable:
|
||||||
"""Decorator to register a tool.
|
"""Decorator to register a tool.
|
||||||
|
|
||||||
Tools can optionally request a Context object by adding a parameter with the Context type annotation.
|
Tools can optionally request a Context object by adding a parameter with the
|
||||||
The context provides access to MCP capabilities like logging, progress reporting, and resource access.
|
Context type annotation. The context provides access to MCP capabilities like
|
||||||
|
logging, progress reporting, and resource access.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name: Optional name for the tool (defaults to function name)
|
name: Optional name for the tool (defaults to function name)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import mcp.server.fastmcp
|
|
||||||
from mcp.server.fastmcp.exceptions import ToolError
|
|
||||||
from mcp.server.fastmcp.utilities.func_metadata import func_metadata, FuncMetadata
|
|
||||||
from pydantic import BaseModel, Field
|
|
||||||
|
|
||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
from typing import TYPE_CHECKING, Any, Callable
|
from typing import TYPE_CHECKING, Any, Callable
|
||||||
|
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
import mcp.server.fastmcp
|
||||||
|
from mcp.server.fastmcp.exceptions import ToolError
|
||||||
|
from mcp.server.fastmcp.utilities.func_metadata import FuncMetadata, func_metadata
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from mcp.server.fastmcp.server import Context
|
from mcp.server.fastmcp.server import Context
|
||||||
|
|
||||||
|
|
@ -19,7 +19,8 @@ class Tool(BaseModel):
|
||||||
description: str = Field(description="Description of what the tool does")
|
description: str = Field(description="Description of what the tool does")
|
||||||
parameters: dict = Field(description="JSON schema for tool parameters")
|
parameters: dict = Field(description="JSON schema for tool parameters")
|
||||||
fn_metadata: FuncMetadata = Field(
|
fn_metadata: FuncMetadata = Field(
|
||||||
description="Metadata about the function including a pydantic model for tool arguments"
|
description="Metadata about the function including a pydantic model for tool"
|
||||||
|
" arguments"
|
||||||
)
|
)
|
||||||
is_async: bool = Field(description="Whether the tool is async")
|
is_async: bool = Field(description="Whether the tool is async")
|
||||||
context_kwarg: str | None = Field(
|
context_kwarg: str | None = Field(
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
|
from collections.abc import Callable
|
||||||
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from mcp.server.fastmcp.exceptions import ToolError
|
from mcp.server.fastmcp.exceptions import ToolError
|
||||||
from mcp.server.fastmcp.tools.base import Tool
|
from mcp.server.fastmcp.tools.base import Tool
|
||||||
|
|
||||||
from typing import Any, Callable, TYPE_CHECKING
|
|
||||||
from collections.abc import Callable
|
|
||||||
|
|
||||||
from mcp.server.fastmcp.utilities.logging import get_logger
|
from mcp.server.fastmcp.utilities.logging import get_logger
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue