Jeremiah Lowin commited on
Commit
4f16c08
·
1 Parent(s): f8c2e94

Use PEP 649 annotations

Browse files
Files changed (1) hide show
  1. src/fastmcp/server/server.py +14 -12
src/fastmcp/server/server.py CHANGED
@@ -1,5 +1,7 @@
1
  """FastMCP - A more ergonomic interface for MCP servers."""
2
 
 
 
3
  import datetime
4
  from collections.abc import AsyncIterator, Awaitable, Callable
5
  from contextlib import (
@@ -63,7 +65,7 @@ class MountedServer:
63
  def __init__(
64
  self,
65
  prefix: str,
66
- server: "FastMCP",
67
  tool_separator: str | None = None,
68
  resource_separator: str | None = None,
69
  prompt_separator: str | None = None,
@@ -149,7 +151,7 @@ class TimedCache:
149
 
150
 
151
  @asynccontextmanager
152
- async def default_lifespan(server: "FastMCP") -> AsyncIterator[Any]:
153
  """Default lifespan context manager that does nothing.
154
 
155
  Args:
@@ -162,8 +164,8 @@ async def default_lifespan(server: "FastMCP") -> AsyncIterator[Any]:
162
 
163
 
164
  def _lifespan_wrapper(
165
- app: "FastMCP",
166
- lifespan: Callable[["FastMCP"], AbstractAsyncContextManager[LifespanResultT]],
167
  ) -> Callable[
168
  [MCPServer[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]
169
  ]:
@@ -183,7 +185,7 @@ class FastMCP(Generic[LifespanResultT]):
183
  instructions: str | None = None,
184
  lifespan: (
185
  Callable[
186
- ["FastMCP[LifespanResultT]"],
187
  AbstractAsyncContextManager[LifespanResultT],
188
  ]
189
  | None
@@ -277,7 +279,7 @@ class FastMCP(Generic[LifespanResultT]):
277
  self._mcp_server.get_prompt()(self._mcp_get_prompt)
278
  self._mcp_server.list_resource_templates()(self._mcp_list_resource_templates)
279
 
280
- def get_context(self) -> "Context[ServerSession, LifespanResultT]":
281
  """
282
  Returns a Context object. Note that the context will only be valid
283
  during a request; outside a request, most methods will error.
@@ -770,7 +772,7 @@ class FastMCP(Generic[LifespanResultT]):
770
  def mount(
771
  self,
772
  prefix: str,
773
- server: "FastMCP[LifespanResultT]",
774
  tool_separator: str | None = None,
775
  resource_separator: str | None = None,
776
  prompt_separator: str | None = None,
@@ -795,7 +797,7 @@ class FastMCP(Generic[LifespanResultT]):
795
  async def import_server(
796
  self,
797
  prefix: str,
798
- server: "FastMCP[LifespanResultT]",
799
  tool_separator: str | None = None,
800
  resource_separator: str | None = None,
801
  prompt_separator: str | None = None,
@@ -869,7 +871,7 @@ class FastMCP(Generic[LifespanResultT]):
869
  @classmethod
870
  def from_openapi(
871
  cls, openapi_spec: dict[str, Any], client: httpx.AsyncClient, **settings: Any
872
- ) -> "FastMCPOpenAPI":
873
  """
874
  Create a FastMCP server from an OpenAPI specification.
875
  """
@@ -879,8 +881,8 @@ class FastMCP(Generic[LifespanResultT]):
879
 
880
  @classmethod
881
  def from_fastapi(
882
- cls, app: "Any", name: str | None = None, **settings: Any
883
- ) -> "FastMCPOpenAPI":
884
  """
885
  Create a FastMCP server from a FastAPI application.
886
  """
@@ -898,7 +900,7 @@ class FastMCP(Generic[LifespanResultT]):
898
  )
899
 
900
  @classmethod
901
- def from_client(cls, client: "Client", **settings: Any) -> "FastMCPProxy":
902
  """
903
  Create a FastMCP proxy server from a FastMCP client.
904
  """
 
1
  """FastMCP - A more ergonomic interface for MCP servers."""
2
 
3
+ from __future__ import annotations
4
+
5
  import datetime
6
  from collections.abc import AsyncIterator, Awaitable, Callable
7
  from contextlib import (
 
65
  def __init__(
66
  self,
67
  prefix: str,
68
+ server: FastMCP,
69
  tool_separator: str | None = None,
70
  resource_separator: str | None = None,
71
  prompt_separator: str | None = None,
 
151
 
152
 
153
  @asynccontextmanager
154
+ async def default_lifespan(server: FastMCP) -> AsyncIterator[Any]:
155
  """Default lifespan context manager that does nothing.
156
 
157
  Args:
 
164
 
165
 
166
  def _lifespan_wrapper(
167
+ app: FastMCP,
168
+ lifespan: Callable[[FastMCP], AbstractAsyncContextManager[LifespanResultT]],
169
  ) -> Callable[
170
  [MCPServer[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]
171
  ]:
 
185
  instructions: str | None = None,
186
  lifespan: (
187
  Callable[
188
+ [FastMCP[LifespanResultT]],
189
  AbstractAsyncContextManager[LifespanResultT],
190
  ]
191
  | None
 
279
  self._mcp_server.get_prompt()(self._mcp_get_prompt)
280
  self._mcp_server.list_resource_templates()(self._mcp_list_resource_templates)
281
 
282
+ def get_context(self) -> Context[ServerSession, LifespanResultT]:
283
  """
284
  Returns a Context object. Note that the context will only be valid
285
  during a request; outside a request, most methods will error.
 
772
  def mount(
773
  self,
774
  prefix: str,
775
+ server: FastMCP[LifespanResultT],
776
  tool_separator: str | None = None,
777
  resource_separator: str | None = None,
778
  prompt_separator: str | None = None,
 
797
  async def import_server(
798
  self,
799
  prefix: str,
800
+ server: FastMCP[LifespanResultT],
801
  tool_separator: str | None = None,
802
  resource_separator: str | None = None,
803
  prompt_separator: str | None = None,
 
871
  @classmethod
872
  def from_openapi(
873
  cls, openapi_spec: dict[str, Any], client: httpx.AsyncClient, **settings: Any
874
+ ) -> FastMCPOpenAPI:
875
  """
876
  Create a FastMCP server from an OpenAPI specification.
877
  """
 
881
 
882
  @classmethod
883
  def from_fastapi(
884
+ cls, app: Any, name: str | None = None, **settings: Any
885
+ ) -> FastMCPOpenAPI:
886
  """
887
  Create a FastMCP server from a FastAPI application.
888
  """
 
900
  )
901
 
902
  @classmethod
903
+ def from_client(cls, client: Client, **settings: Any) -> FastMCPProxy:
904
  """
905
  Create a FastMCP proxy server from a FastMCP client.
906
  """