style: Fix imports and line length formatting

This commit is contained in:
David Soria Parra 2024-12-19 22:33:40 +00:00
commit a79f51f55f
No known key found for this signature in database
37 changed files with 232 additions and 125 deletions

View file

@ -4,8 +4,10 @@ FastMCP Complex inputs Example
Demonstrates validation via pydantic with complex models.
"""
from pydantic import BaseModel, Field
from typing import Annotated
from pydantic import BaseModel, Field
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("Shrimp Tank")

View file

@ -6,7 +6,8 @@
"""
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
@ -111,7 +112,8 @@ class MemoryNode(BaseModel):
if self.id is None:
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)
RETURNING id
""",
@ -336,7 +338,8 @@ async def initialize_database():
timestamp DOUBLE PRECISION 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:
await pool.close()

View file

@ -1,6 +1,5 @@
from mcp.server.fastmcp import FastMCP
# Create an MCP server
mcp = FastMCP("Demo")

View file

@ -5,10 +5,10 @@ Give Claude a tool to capture and view screenshots.
"""
import io
from mcp.server.fastmcp import FastMCP
from mcp.server.fastmcp.utilities.types import Image
# Create server
mcp = FastMCP("Screenshot Demo", dependencies=["pyautogui", "Pillow"])

View file

@ -4,7 +4,6 @@ FastMCP Echo Server
from mcp.server.fastmcp import FastMCP
# Create server
mcp = FastMCP("Echo Server")

View file

@ -19,6 +19,7 @@ Visit https://surgemsg.com/ and click "Get Started" to obtain these values.
"""
from typing import Annotated
import httpx
from pydantic import BeforeValidator
from pydantic_settings import BaseSettings, SettingsConfigDict

View file

@ -1,8 +1,8 @@
import anyio
import click
import mcp.types as types
from pydantic import AnyUrl
from mcp.server.lowlevel import Server
from pydantic import AnyUrl
SAMPLE_RESOURCES = {
"greeting": "Hello! This is a sample text resource.",

View file

@ -47,7 +47,6 @@ dev-dependencies = [
"trio>=0.26.2",
"pytest-flakefinder>=1.1.0",
"pytest-xdist>=3.6.1",
"pytest-asyncio>=0.24.0",
]
[build-system]

View file

@ -2,6 +2,5 @@
from .cli import app
if __name__ == "__main__":
app()

View file

@ -48,8 +48,8 @@ def update_claude_config(
config_dir = get_claude_config_path()
if not config_dir:
raise RuntimeError(
"Claude Desktop config directory not found. Please ensure Claude Desktop "
"is installed and has been run at least once to initialize its configuration."
"Claude Desktop config directory not found. Please ensure Claude Desktop"
" is installed and has been run at least once to initialize its config."
)
config_file = config_dir / "claude_desktop_config.json"

View file

@ -295,7 +295,8 @@ def run(
"""Run a MCP server.
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
Note: This command runs the server directly. You are responsible for ensuring
@ -346,7 +347,8 @@ def install(
typer.Option(
"--name",
"-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,
with_editable: Annotated[
@ -410,7 +412,8 @@ def install(
logger.error("Claude app not found")
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
server = None
if not name:
@ -419,7 +422,8 @@ def install(
name = server.name
except (ImportError, ModuleNotFoundError) as e:
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)},
)
name = file.stem

View file

@ -1,4 +1,4 @@
from .lowlevel import Server, NotificationOptions
from .fastmcp import FastMCP
from .lowlevel import NotificationOptions, Server
__all__ = ["Server", "FastMCP", "NotificationOptions"]

View file

@ -1,7 +1,8 @@
"""FastMCP - A more ergonomic interface for MCP servers."""
from importlib.metadata import version
from .server import FastMCP, Context
from .server import Context, FastMCP
from .utilities.types import Image
__version__ = version("mcp")

View file

@ -1,13 +1,14 @@
"""Base classes for FastMCP prompts."""
import json
from typing import Any, Literal, Sequence, Awaitable
import inspect
import json
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
from pydantic import BaseModel, Field, TypeAdapter, validate_call
from mcp.types import EmbeddedResource, ImageContent, TextContent
CONTENT_TYPES = TextContent | ImageContent | EmbeddedResource

View file

@ -1,14 +1,14 @@
from .base import Resource
from .types import (
TextResource,
BinaryResource,
FunctionResource,
FileResource,
HttpResource,
DirectoryResource,
)
from .templates import ResourceTemplate
from .resource_manager import ResourceManager
from .templates import ResourceTemplate
from .types import (
BinaryResource,
DirectoryResource,
FileResource,
FunctionResource,
HttpResource,
TextResource,
)
__all__ = [
"Resource",

View file

@ -1,7 +1,6 @@
"""Resource manager functionality."""
from typing import Callable
from collections.abc import Iterable
from pydantic import AnyUrl

View file

@ -1,11 +1,11 @@
"""Concrete resource implementations."""
import anyio
import json
from pathlib import Path
from typing import Any, Callable
from collections.abc import Callable
from pathlib import Path
from typing import Any
import anyio
import httpx
import pydantic.json
import pydantic_core

View file

@ -1,17 +1,25 @@
"""FastMCP - A more ergonomic interface for MCP servers."""
import anyio
import functools
import inspect
import json
import re
from itertools import chain
from typing import Any, Callable, Literal, Sequence
from collections.abc import Iterable
import anyio
import pydantic_core
from pydantic import Field
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.sse import SseServerTransport
from mcp.server.stdio import stdio_server
@ -24,6 +32,8 @@ from mcp.types import (
)
from mcp.types import (
Prompt as MCPPrompt,
)
from mcp.types import (
PromptArgument as MCPPromptArgument,
)
from mcp.types import (
@ -35,16 +45,6 @@ from mcp.types import (
from mcp.types import (
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__)
@ -226,8 +226,9 @@ class FastMCP:
def tool(self, name: str | None = None, description: str | None = None) -> Callable:
"""Decorator to register a tool.
Tools can optionally request a Context object by adding a parameter with the Context type annotation.
The context provides access to MCP capabilities like logging, progress reporting, and resource access.
Tools can optionally request a Context object by adding a parameter with the
Context type annotation. The context provides access to MCP capabilities like
logging, progress reporting, and resource access.
Args:
name: Optional name for the tool (defaults to function name)

View file

@ -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
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:
from mcp.server.fastmcp.server import Context
@ -19,7 +19,8 @@ class Tool(BaseModel):
description: str = Field(description="Description of what the tool does")
parameters: dict = Field(description="JSON schema for tool parameters")
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")
context_kwarg: str | None = Field(

View file

@ -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.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
if TYPE_CHECKING:

Some files were not shown because too many files have changed in this diff Show more