44
55import inspect
66import re
7- from collections .abc import AsyncIterator , Awaitable , Callable , Collection , Iterable , Sequence
7+ from collections .abc import (
8+ AsyncIterator ,
9+ Awaitable ,
10+ Callable ,
11+ Collection ,
12+ Iterable ,
13+ Sequence ,
14+ )
815from contextlib import AbstractAsyncContextManager , asynccontextmanager
916from typing import Any , Generic , Literal
1017
2229from starlette .types import Receive , Scope , Send
2330
2431from mcp .server .auth .middleware .auth_context import AuthContextMiddleware
25- from mcp .server .auth .middleware .bearer_auth import BearerAuthBackend , RequireAuthMiddleware
26- from mcp .server .auth .provider import OAuthAuthorizationServerProvider , ProviderTokenVerifier , TokenVerifier
32+ from mcp .server .auth .middleware .bearer_auth import (
33+ BearerAuthBackend ,
34+ RequireAuthMiddleware ,
35+ )
36+ from mcp .server .auth .provider import (
37+ OAuthAuthorizationServerProvider ,
38+ ProviderTokenVerifier ,
39+ TokenVerifier ,
40+ )
2741from mcp .server .auth .settings import AuthSettings
28- from mcp .server .elicitation import ElicitationResult , ElicitSchemaModelT , elicit_with_validation
42+ from mcp .server .elicitation import (
43+ ElicitationResult ,
44+ ElicitSchemaModelT ,
45+ elicit_with_validation ,
46+ )
2947from mcp .server .fastmcp .exceptions import ResourceError
3048from mcp .server .fastmcp .prompts import Prompt , PromptManager
3149from mcp .server .fastmcp .resources import FunctionResource , Resource , ResourceManager
@@ -112,7 +130,9 @@ def lifespan_wrapper(
112130 lifespan : Callable [[FastMCP [LifespanResultT ]], AbstractAsyncContextManager [LifespanResultT ]],
113131) -> Callable [[MCPServer [LifespanResultT , Request ]], AbstractAsyncContextManager [LifespanResultT ]]:
114132 @asynccontextmanager
115- async def wrap (_ : MCPServer [LifespanResultT , Request ]) -> AsyncIterator [LifespanResultT ]:
133+ async def wrap (
134+ _ : MCPServer [LifespanResultT , Request ],
135+ ) -> AsyncIterator [LifespanResultT ]:
116136 async with lifespan (app ) as context :
117137 yield context
118138
@@ -126,7 +146,7 @@ def __init__( # noqa: PLR0913
126146 instructions : str | None = None ,
127147 website_url : str | None = None ,
128148 icons : list [Icon ] | None = None ,
129- auth_server_provider : OAuthAuthorizationServerProvider [Any , Any , Any ] | None = None ,
149+ auth_server_provider : ( OAuthAuthorizationServerProvider [Any , Any , Any ] | None ) = None ,
130150 token_verifier : TokenVerifier | None = None ,
131151 event_store : EventStore | None = None ,
132152 * ,
@@ -145,7 +165,7 @@ def __init__( # noqa: PLR0913
145165 warn_on_duplicate_tools : bool = True ,
146166 warn_on_duplicate_prompts : bool = True ,
147167 dependencies : Collection [str ] = (),
148- lifespan : Callable [[FastMCP [LifespanResultT ]], AbstractAsyncContextManager [LifespanResultT ]] | None = None ,
168+ lifespan : ( Callable [[FastMCP [LifespanResultT ]], AbstractAsyncContextManager [LifespanResultT ]] | None ) = None ,
149169 auth : AuthSettings | None = None ,
150170 transport_security : TransportSecuritySettings | None = None ,
151171 ):
@@ -290,6 +310,7 @@ async def list_tools(self) -> list[MCPTool]:
290310 outputSchema = info .output_schema ,
291311 annotations = info .annotations ,
292312 icons = info .icons ,
313+ _meta = info .meta ,
293314 )
294315 for info in tools
295316 ]
@@ -365,6 +386,7 @@ def add_tool(
365386 description : str | None = None ,
366387 annotations : ToolAnnotations | None = None ,
367388 icons : list [Icon ] | None = None ,
389+ meta : dict [str , Any ] | None = None ,
368390 structured_output : bool | None = None ,
369391 ) -> None :
370392 """Add a tool to the server.
@@ -390,6 +412,7 @@ def add_tool(
390412 description = description ,
391413 annotations = annotations ,
392414 icons = icons ,
415+ meta = meta ,
393416 structured_output = structured_output ,
394417 )
395418
@@ -411,6 +434,7 @@ def tool(
411434 description : str | None = None ,
412435 annotations : ToolAnnotations | None = None ,
413436 icons : list [Icon ] | None = None ,
437+ meta : dict [str , Any ] | None = None ,
414438 structured_output : bool | None = None ,
415439 ) -> Callable [[AnyFunction ], AnyFunction ]:
416440 """Decorator to register a tool.
@@ -458,6 +482,7 @@ def decorator(fn: AnyFunction) -> AnyFunction:
458482 description = description ,
459483 annotations = annotations ,
460484 icons = icons ,
485+ meta = meta ,
461486 structured_output = structured_output ,
462487 )
463488 return fn
@@ -1169,7 +1194,10 @@ async def elicit(
11691194 """
11701195
11711196 return await elicit_with_validation (
1172- session = self .request_context .session , message = message , schema = schema , related_request_id = self .request_id
1197+ session = self .request_context .session ,
1198+ message = message ,
1199+ schema = schema ,
1200+ related_request_id = self .request_id ,
11731201 )
11741202
11751203 async def log (
0 commit comments