Jeremiah Lowin commited on
Commit
abc4a6d
·
unverified ·
1 Parent(s): 6dfadd8

Remove unnecessary asserts (#1484)

Browse files
.github/workflows/run-static.yml CHANGED
@@ -77,6 +77,7 @@ jobs:
77
  # Check if docs.json content changed (ignoring formatting)
78
  if ! jq --sort-keys . docs/docs.json.orig | diff -q - <(jq --sort-keys . docs/docs.json) > /dev/null 2>&1; then
79
  echo "❌ docs.json content has changed!"
 
80
  echo "Run `just api-ref-all` to regenerate the SDK docs, then commit the changes. Note: you may need to install `just` (https://github.com/casey/just)"
81
  exit 1
82
  fi
 
77
  # Check if docs.json content changed (ignoring formatting)
78
  if ! jq --sort-keys . docs/docs.json.orig | diff -q - <(jq --sort-keys . docs/docs.json) > /dev/null 2>&1; then
79
  echo "❌ docs.json content has changed!"
80
+ echo ""
81
  echo "Run `just api-ref-all` to regenerate the SDK docs, then commit the changes. Note: you may need to install `just` (https://github.com/casey/just)"
82
  exit 1
83
  fi
docs/python-sdk/fastmcp-cli-run.mdx CHANGED
@@ -53,7 +53,7 @@ Import a MCP server from a file.
53
  - The server object (or result of calling a factory function)
54
 
55
 
56
- ### `run_with_uv` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L179" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
57
 
58
  ```python
59
  run_with_uv(server_spec: str, python_version: str | None = None, with_packages: list[str] | None = None, with_requirements: Path | None = None, project: Path | None = None, transport: TransportType | None = None, host: str | None = None, port: int | None = None, path: str | None = None, log_level: LogLevelType | None = None, show_banner: bool = True) -> None
@@ -76,7 +76,7 @@ Run a MCP server using uv run subprocess.
76
  - `show_banner`: Whether to show the server banner
77
 
78
 
79
- ### `create_client_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L257" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
80
 
81
  ```python
82
  create_client_server(url: str) -> Any
@@ -92,7 +92,7 @@ Create a FastMCP server from a client URL.
92
  - A FastMCP server instance
93
 
94
 
95
- ### `create_mcp_config_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L277" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
96
 
97
  ```python
98
  create_mcp_config_server(mcp_config_path: Path) -> FastMCP[None]
@@ -102,7 +102,7 @@ create_mcp_config_server(mcp_config_path: Path) -> FastMCP[None]
102
  Create a FastMCP server from a MCPConfig.
103
 
104
 
105
- ### `import_server_with_args` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L288" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
106
 
107
  ```python
108
  import_server_with_args(file: Path, server_or_factory: str | None = None, server_args: list[str] | None = None) -> Any
@@ -120,7 +120,7 @@ Import a server with optional command line arguments.
120
  - The imported server object
121
 
122
 
123
- ### `run_command` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L314" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
124
 
125
  ```python
126
  run_command(server_spec: str, transport: TransportType | None = None, host: str | None = None, port: int | None = None, path: str | None = None, log_level: LogLevelType | None = None, server_args: list[str] | None = None, show_banner: bool = True, use_direct_import: bool = False) -> None
@@ -141,7 +141,7 @@ Run a MCP server or connect to a remote one.
141
  - `use_direct_import`: Whether to use direct import instead of subprocess
142
 
143
 
144
- ### `run_v1_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L379" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
145
 
146
  ```python
147
  run_v1_server(server: FastMCP1x, host: str | None = None, port: int | None = None, transport: TransportType | None = None) -> None
 
53
  - The server object (or result of calling a factory function)
54
 
55
 
56
+ ### `run_with_uv` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L174" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
57
 
58
  ```python
59
  run_with_uv(server_spec: str, python_version: str | None = None, with_packages: list[str] | None = None, with_requirements: Path | None = None, project: Path | None = None, transport: TransportType | None = None, host: str | None = None, port: int | None = None, path: str | None = None, log_level: LogLevelType | None = None, show_banner: bool = True) -> None
 
76
  - `show_banner`: Whether to show the server banner
77
 
78
 
79
+ ### `create_client_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L252" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
80
 
81
  ```python
82
  create_client_server(url: str) -> Any
 
92
  - A FastMCP server instance
93
 
94
 
95
+ ### `create_mcp_config_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L272" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
96
 
97
  ```python
98
  create_mcp_config_server(mcp_config_path: Path) -> FastMCP[None]
 
102
  Create a FastMCP server from a MCPConfig.
103
 
104
 
105
+ ### `import_server_with_args` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L283" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
106
 
107
  ```python
108
  import_server_with_args(file: Path, server_or_factory: str | None = None, server_args: list[str] | None = None) -> Any
 
120
  - The imported server object
121
 
122
 
123
+ ### `run_command` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L309" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
124
 
125
  ```python
126
  run_command(server_spec: str, transport: TransportType | None = None, host: str | None = None, port: int | None = None, path: str | None = None, log_level: LogLevelType | None = None, server_args: list[str] | None = None, show_banner: bool = True, use_direct_import: bool = False) -> None
 
141
  - `use_direct_import`: Whether to use direct import instead of subprocess
142
 
143
 
144
+ ### `run_v1_server` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/cli/run.py#L374" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
145
 
146
  ```python
147
  run_v1_server(server: FastMCP1x, host: str | None = None, port: int | None = None, transport: TransportType | None = None) -> None
docs/python-sdk/fastmcp-server-auth-auth.mdx CHANGED
@@ -107,7 +107,7 @@ the authorization servers that issue valid tokens.
107
 
108
  **Methods:**
109
 
110
- #### `verify_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L161" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
111
 
112
  ```python
113
  verify_token(self, token: str) -> AccessToken | None
@@ -116,7 +116,7 @@ verify_token(self, token: str) -> AccessToken | None
116
  Verify token using the configured token verifier.
117
 
118
 
119
- #### `get_routes` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L165" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
120
 
121
  ```python
122
  get_routes(self) -> list[Route]
@@ -129,7 +129,7 @@ Subclasses can override this method to add additional routes by calling
129
  super().get_routes() and extending the returned list.
130
 
131
 
132
- ### `OAuthProvider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L183" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
133
 
134
 
135
  OAuth Authorization Server provider.
@@ -140,7 +140,7 @@ authorization flows, token issuance, and token verification.
140
 
141
  **Methods:**
142
 
143
- #### `verify_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L250" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
144
 
145
  ```python
146
  verify_token(self, token: str) -> AccessToken | None
@@ -158,7 +158,7 @@ to our existing load_access_token method.
158
  - AccessToken object if valid, None if invalid or expired
159
 
160
 
161
- #### `get_routes` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L265" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
162
 
163
  ```python
164
  get_routes(self) -> list[Route]
 
107
 
108
  **Methods:**
109
 
110
+ #### `verify_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L163" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
111
 
112
  ```python
113
  verify_token(self, token: str) -> AccessToken | None
 
116
  Verify token using the configured token verifier.
117
 
118
 
119
+ #### `get_routes` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L167" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
120
 
121
  ```python
122
  get_routes(self) -> list[Route]
 
129
  super().get_routes() and extending the returned list.
130
 
131
 
132
+ ### `OAuthProvider` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L184" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
133
 
134
 
135
  OAuth Authorization Server provider.
 
140
 
141
  **Methods:**
142
 
143
+ #### `verify_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L251" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
144
 
145
  ```python
146
  verify_token(self, token: str) -> AccessToken | None
 
158
  - AccessToken object if valid, None if invalid or expired
159
 
160
 
161
+ #### `get_routes` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/auth.py#L266" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
162
 
163
  ```python
164
  get_routes(self) -> list[Route]
docs/python-sdk/fastmcp-server-context.mdx CHANGED
@@ -111,7 +111,7 @@ Read a resource by URI.
111
  - The resource content as either text or bytes
112
 
113
 
114
- #### `log` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L194" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
115
 
116
  ```python
117
  log(self, message: str, level: LoggingLevel | None = None, logger_name: str | None = None, extra: Mapping[str, Any] | None = None) -> None
@@ -127,7 +127,7 @@ Send a log message to the client.
127
  - `extra`: Optional mapping for additional arguments
128
 
129
 
130
- #### `client_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L221" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
131
 
132
  ```python
133
  client_id(self) -> str | None
@@ -136,7 +136,7 @@ client_id(self) -> str | None
136
  Get the client ID if available.
137
 
138
 
139
- #### `request_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L230" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
140
 
141
  ```python
142
  request_id(self) -> str
@@ -145,7 +145,7 @@ request_id(self) -> str
145
  Get the unique ID for this request.
146
 
147
 
148
- #### `session_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L235" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
149
 
150
  ```python
151
  session_id(self) -> str
@@ -162,7 +162,7 @@ the same client session.
162
  - for other transports.
163
 
164
 
165
- #### `session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L279" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
166
 
167
  ```python
168
  session(self) -> ServerSession
@@ -171,7 +171,7 @@ session(self) -> ServerSession
171
  Access to the underlying session for advanced usage.
172
 
173
 
174
- #### `debug` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L284" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
175
 
176
  ```python
177
  debug(self, message: str, logger_name: str | None = None, extra: Mapping[str, Any] | None = None) -> None
@@ -180,7 +180,7 @@ debug(self, message: str, logger_name: str | None = None, extra: Mapping[str, An
180
  Send a debug log message.
181
 
182
 
183
- #### `info` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L295" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
184
 
185
  ```python
186
  info(self, message: str, logger_name: str | None = None, extra: Mapping[str, Any] | None = None) -> None
@@ -189,7 +189,7 @@ info(self, message: str, logger_name: str | None = None, extra: Mapping[str, Any
189
  Send an info log message.
190
 
191
 
192
- #### `warning` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L306" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
193
 
194
  ```python
195
  warning(self, message: str, logger_name: str | None = None, extra: Mapping[str, Any] | None = None) -> None
@@ -198,7 +198,7 @@ warning(self, message: str, logger_name: str | None = None, extra: Mapping[str,
198
  Send a warning log message.
199
 
200
 
201
- #### `error` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L317" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
202
 
203
  ```python
204
  error(self, message: str, logger_name: str | None = None, extra: Mapping[str, Any] | None = None) -> None
@@ -207,7 +207,7 @@ error(self, message: str, logger_name: str | None = None, extra: Mapping[str, An
207
  Send an error log message.
208
 
209
 
210
- #### `list_roots` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L328" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
211
 
212
  ```python
213
  list_roots(self) -> list[Root]
@@ -216,7 +216,7 @@ list_roots(self) -> list[Root]
216
  List the roots available to the server, as indicated by the client.
217
 
218
 
219
- #### `send_tool_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L333" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
220
 
221
  ```python
222
  send_tool_list_changed(self) -> None
@@ -225,7 +225,7 @@ send_tool_list_changed(self) -> None
225
  Send a tool list changed notification to the client.
226
 
227
 
228
- #### `send_resource_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L337" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
229
 
230
  ```python
231
  send_resource_list_changed(self) -> None
@@ -234,7 +234,7 @@ send_resource_list_changed(self) -> None
234
  Send a resource list changed notification to the client.
235
 
236
 
237
- #### `send_prompt_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L341" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
238
 
239
  ```python
240
  send_prompt_list_changed(self) -> None
@@ -243,7 +243,7 @@ send_prompt_list_changed(self) -> None
243
  Send a prompt list changed notification to the client.
244
 
245
 
246
- #### `sample` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L345" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
247
 
248
  ```python
249
  sample(self, messages: str | list[str | SamplingMessage], system_prompt: str | None = None, include_context: IncludeContext | None = None, temperature: float | None = None, max_tokens: int | None = None, model_preferences: ModelPreferences | str | list[str] | None = None) -> ContentBlock
@@ -256,25 +256,25 @@ completion from the client. The client must be appropriately configured,
256
  or the request will error.
257
 
258
 
259
- #### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L392" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
260
 
261
  ```python
262
  elicit(self, message: str, response_type: None) -> AcceptedElicitation[dict[str, Any]] | DeclinedElicitation | CancelledElicitation
263
  ```
264
 
265
- #### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L404" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
266
 
267
  ```python
268
  elicit(self, message: str, response_type: type[T]) -> AcceptedElicitation[T] | DeclinedElicitation | CancelledElicitation
269
  ```
270
 
271
- #### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L414" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
272
 
273
  ```python
274
  elicit(self, message: str, response_type: list[str]) -> AcceptedElicitation[str] | DeclinedElicitation | CancelledElicitation
275
  ```
276
 
277
- #### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L423" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
278
 
279
  ```python
280
  elicit(self, message: str, response_type: type[T] | list[str] | None = None) -> AcceptedElicitation[T] | AcceptedElicitation[dict[str, Any]] | AcceptedElicitation[str] | DeclinedElicitation | CancelledElicitation
@@ -303,7 +303,7 @@ type or dataclass or BaseModel. If it is a primitive type, an
303
  object schema with a single "value" field will be generated.
304
 
305
 
306
- #### `get_http_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L516" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
307
 
308
  ```python
309
  get_http_request(self) -> Request
@@ -312,7 +312,7 @@ get_http_request(self) -> Request
312
  Get the active starlette request.
313
 
314
 
315
- #### `set_state` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L531" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
316
 
317
  ```python
318
  set_state(self, key: str, value: Any) -> None
@@ -321,7 +321,7 @@ set_state(self, key: str, value: Any) -> None
321
  Set a value in the context state.
322
 
323
 
324
- #### `get_state` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L535" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
325
 
326
  ```python
327
  get_state(self, key: str) -> Any
 
111
  - The resource content as either text or bytes
112
 
113
 
114
+ #### `log` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L195" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
115
 
116
  ```python
117
  log(self, message: str, level: LoggingLevel | None = None, logger_name: str | None = None, extra: Mapping[str, Any] | None = None) -> None
 
127
  - `extra`: Optional mapping for additional arguments
128
 
129
 
130
+ #### `client_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L222" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
131
 
132
  ```python
133
  client_id(self) -> str | None
 
136
  Get the client ID if available.
137
 
138
 
139
+ #### `request_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L231" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
140
 
141
  ```python
142
  request_id(self) -> str
 
145
  Get the unique ID for this request.
146
 
147
 
148
+ #### `session_id` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L236" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
149
 
150
  ```python
151
  session_id(self) -> str
 
162
  - for other transports.
163
 
164
 
165
+ #### `session` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L280" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
166
 
167
  ```python
168
  session(self) -> ServerSession
 
171
  Access to the underlying session for advanced usage.
172
 
173
 
174
+ #### `debug` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L285" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
175
 
176
  ```python
177
  debug(self, message: str, logger_name: str | None = None, extra: Mapping[str, Any] | None = None) -> None
 
180
  Send a debug log message.
181
 
182
 
183
+ #### `info` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L296" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
184
 
185
  ```python
186
  info(self, message: str, logger_name: str | None = None, extra: Mapping[str, Any] | None = None) -> None
 
189
  Send an info log message.
190
 
191
 
192
+ #### `warning` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L307" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
193
 
194
  ```python
195
  warning(self, message: str, logger_name: str | None = None, extra: Mapping[str, Any] | None = None) -> None
 
198
  Send a warning log message.
199
 
200
 
201
+ #### `error` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L318" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
202
 
203
  ```python
204
  error(self, message: str, logger_name: str | None = None, extra: Mapping[str, Any] | None = None) -> None
 
207
  Send an error log message.
208
 
209
 
210
+ #### `list_roots` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L329" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
211
 
212
  ```python
213
  list_roots(self) -> list[Root]
 
216
  List the roots available to the server, as indicated by the client.
217
 
218
 
219
+ #### `send_tool_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L334" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
220
 
221
  ```python
222
  send_tool_list_changed(self) -> None
 
225
  Send a tool list changed notification to the client.
226
 
227
 
228
+ #### `send_resource_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L338" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
229
 
230
  ```python
231
  send_resource_list_changed(self) -> None
 
234
  Send a resource list changed notification to the client.
235
 
236
 
237
+ #### `send_prompt_list_changed` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L342" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
238
 
239
  ```python
240
  send_prompt_list_changed(self) -> None
 
243
  Send a prompt list changed notification to the client.
244
 
245
 
246
+ #### `sample` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L346" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
247
 
248
  ```python
249
  sample(self, messages: str | list[str | SamplingMessage], system_prompt: str | None = None, include_context: IncludeContext | None = None, temperature: float | None = None, max_tokens: int | None = None, model_preferences: ModelPreferences | str | list[str] | None = None) -> ContentBlock
 
256
  or the request will error.
257
 
258
 
259
+ #### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L393" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
260
 
261
  ```python
262
  elicit(self, message: str, response_type: None) -> AcceptedElicitation[dict[str, Any]] | DeclinedElicitation | CancelledElicitation
263
  ```
264
 
265
+ #### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L405" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
266
 
267
  ```python
268
  elicit(self, message: str, response_type: type[T]) -> AcceptedElicitation[T] | DeclinedElicitation | CancelledElicitation
269
  ```
270
 
271
+ #### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L415" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
272
 
273
  ```python
274
  elicit(self, message: str, response_type: list[str]) -> AcceptedElicitation[str] | DeclinedElicitation | CancelledElicitation
275
  ```
276
 
277
+ #### `elicit` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L424" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
278
 
279
  ```python
280
  elicit(self, message: str, response_type: type[T] | list[str] | None = None) -> AcceptedElicitation[T] | AcceptedElicitation[dict[str, Any]] | AcceptedElicitation[str] | DeclinedElicitation | CancelledElicitation
 
303
  object schema with a single "value" field will be generated.
304
 
305
 
306
+ #### `get_http_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L517" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
307
 
308
  ```python
309
  get_http_request(self) -> Request
 
312
  Get the active starlette request.
313
 
314
 
315
+ #### `set_state` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L532" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
316
 
317
  ```python
318
  set_state(self, key: str, value: Any) -> None
 
321
  Set a value in the context state.
322
 
323
 
324
+ #### `get_state` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/context.py#L536" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
325
 
326
  ```python
327
  get_state(self, key: str) -> Any
docs/python-sdk/fastmcp-utilities-components.mdx CHANGED
@@ -55,7 +55,7 @@ Create a copy of the component.
55
  - `key`: The key to use for the copy.
56
 
57
 
58
- #### `enable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L126" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
59
 
60
  ```python
61
  enable(self) -> None
@@ -64,7 +64,7 @@ enable(self) -> None
64
  Enable the component.
65
 
66
 
67
- #### `disable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L130" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
68
 
69
  ```python
70
  disable(self) -> None
@@ -73,7 +73,7 @@ disable(self) -> None
73
  Disable the component.
74
 
75
 
76
- #### `copy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L134" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
77
 
78
  ```python
79
  copy(self) -> Self
@@ -82,7 +82,7 @@ copy(self) -> Self
82
  Create a copy of the component.
83
 
84
 
85
- ### `MirroredComponent` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L139" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
86
 
87
 
88
  Base class for components that are mirrored from a remote server.
@@ -93,7 +93,7 @@ to create a local version you can modify.
93
 
94
  **Methods:**
95
 
96
- #### `enable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L152" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
97
 
98
  ```python
99
  enable(self) -> None
@@ -102,7 +102,7 @@ enable(self) -> None
102
  Enable the component.
103
 
104
 
105
- #### `disable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L161" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
106
 
107
  ```python
108
  disable(self) -> None
@@ -111,7 +111,7 @@ disable(self) -> None
111
  Disable the component.
112
 
113
 
114
- #### `copy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L170" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
115
 
116
  ```python
117
  copy(self) -> Self
 
55
  - `key`: The key to use for the copy.
56
 
57
 
58
+ #### `enable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L127" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
59
 
60
  ```python
61
  enable(self) -> None
 
64
  Enable the component.
65
 
66
 
67
+ #### `disable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L131" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
68
 
69
  ```python
70
  disable(self) -> None
 
73
  Disable the component.
74
 
75
 
76
+ #### `copy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L135" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
77
 
78
  ```python
79
  copy(self) -> Self
 
82
  Create a copy of the component.
83
 
84
 
85
+ ### `MirroredComponent` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L140" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
86
 
87
 
88
  Base class for components that are mirrored from a remote server.
 
93
 
94
  **Methods:**
95
 
96
+ #### `enable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L153" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
97
 
98
  ```python
99
  enable(self) -> None
 
102
  Enable the component.
103
 
104
 
105
+ #### `disable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L162" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
106
 
107
  ```python
108
  disable(self) -> None
 
111
  Disable the component.
112
 
113
 
114
+ #### `copy` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/components.py#L171" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
115
 
116
  ```python
117
  copy(self) -> Self
src/fastmcp/cli/run.py CHANGED
@@ -80,9 +80,6 @@ async def import_server(file: Path, server_or_factory: str | None = None) -> Any
80
  logger.error("Could not load module", extra={"file": str(file)})
81
  sys.exit(1)
82
 
83
- assert spec is not None
84
- assert spec.loader is not None
85
-
86
  module = importlib.util.module_from_spec(spec)
87
  spec.loader.exec_module(module)
88
 
@@ -102,8 +99,6 @@ async def import_server(file: Path, server_or_factory: str | None = None) -> Any
102
  )
103
  sys.exit(1)
104
 
105
- assert server_or_factory is not None
106
-
107
  # Handle module:object syntax
108
  if ":" in server_or_factory:
109
  module_name, object_name = server_or_factory.split(":", 1)
 
80
  logger.error("Could not load module", extra={"file": str(file)})
81
  sys.exit(1)
82
 
 
 
 
83
  module = importlib.util.module_from_spec(spec)
84
  spec.loader.exec_module(module)
85
 
 
99
  )
100
  sys.exit(1)
101
 
 
 
102
  # Handle module:object syntax
103
  if ":" in server_or_factory:
104
  module_name, object_name = server_or_factory.split(":", 1)
src/fastmcp/experimental/server/openapi/routing.py CHANGED
@@ -110,8 +110,6 @@ def _determine_route_type(
110
  # Tags don't match, continue to next mapping
111
  continue
112
 
113
- # We know mcp_type is not None here due to post_init validation
114
- assert route_map.mcp_type is not None
115
  logger.debug(
116
  f"Route {route.method} {route.path} mapped to {route_map.mcp_type.name}"
117
  )
 
110
  # Tags don't match, continue to next mapping
111
  continue
112
 
 
 
113
  logger.debug(
114
  f"Route {route.method} {route.path} mapped to {route_map.mcp_type.name}"
115
  )
src/fastmcp/experimental/server/openapi/server.py CHANGED
@@ -163,8 +163,6 @@ class FastMCPOpenAPI(FastMCP):
163
  # Determine route type based on mappings or default rules
164
  route_map = _determine_route_type(route, route_maps)
165
 
166
- # TODO: remove this once RouteType is removed and mcp_type is typed as MCPType without | None
167
- assert route_map.mcp_type is not None
168
  route_type = route_map.mcp_type
169
 
170
  # Call route_map_fn if provided
 
163
  # Determine route type based on mappings or default rules
164
  route_map = _determine_route_type(route, route_maps)
165
 
 
 
166
  route_type = route_map.mcp_type
167
 
168
  # Call route_map_fn if provided
src/fastmcp/server/auth/auth.py CHANGED
@@ -135,6 +135,8 @@ class RemoteAuthProvider(AuthProvider):
135
  the authorization servers that issue valid tokens.
136
  """
137
 
 
 
138
  def __init__(
139
  self,
140
  token_verifier: TokenVerifier,
@@ -169,7 +171,6 @@ class RemoteAuthProvider(AuthProvider):
169
  Subclasses can override this method to add additional routes by calling
170
  super().get_routes() and extending the returned list.
171
  """
172
- assert self.resource_server_url is not None
173
 
174
  return create_protected_resource_routes(
175
  resource_url=self.resource_server_url,
 
135
  the authorization servers that issue valid tokens.
136
  """
137
 
138
+ resource_server_url: AnyHttpUrl
139
+
140
  def __init__(
141
  self,
142
  token_verifier: TokenVerifier,
 
171
  Subclasses can override this method to add additional routes by calling
172
  super().get_routes() and extending the returned list.
173
  """
 
174
 
175
  return create_protected_resource_routes(
176
  resource_url=self.resource_server_url,
src/fastmcp/server/context.py CHANGED
@@ -188,7 +188,8 @@ class Context:
188
  Returns:
189
  The resource content as either text or bytes
190
  """
191
- assert self.fastmcp is not None, "Context is not available outside of a request"
 
192
  return await self.fastmcp._mcp_read_resource(uri)
193
 
194
  async def log(
 
188
  Returns:
189
  The resource content as either text or bytes
190
  """
191
+ if self.fastmcp is None:
192
+ raise ValueError("Context is not available outside of a request")
193
  return await self.fastmcp._mcp_read_resource(uri)
194
 
195
  async def log(
src/fastmcp/utilities/components.py CHANGED
@@ -117,7 +117,8 @@ class FastMCPComponent(FastMCPBaseModel):
117
  def __eq__(self, other: object) -> bool:
118
  if type(self) is not type(other):
119
  return False
120
- assert isinstance(other, type(self))
 
121
  return self.model_dump() == other.model_dump()
122
 
123
  def __repr__(self) -> str:
 
117
  def __eq__(self, other: object) -> bool:
118
  if type(self) is not type(other):
119
  return False
120
+ if not isinstance(other, type(self)):
121
+ return False
122
  return self.model_dump() == other.model_dump()
123
 
124
  def __repr__(self) -> str:
src/fastmcp/utilities/json_schema_type.py CHANGED
@@ -449,7 +449,8 @@ def _create_pydantic_model(
449
  ) -> type:
450
  """Create Pydantic BaseModel from object schema with additionalProperties."""
451
  name = name or schema.get("title", "Root")
452
- assert name is not None # Should not be None after the or operation
 
453
  sanitized_name = _sanitize_name(name)
454
  schema_hash = _hash_schema(schema)
455
  cache_key = (schema_hash, sanitized_name)
@@ -507,7 +508,8 @@ def _create_dataclass(
507
  """Create dataclass from object schema."""
508
  name = name or schema.get("title", "Root")
509
  # Sanitize name for class creation
510
- assert name is not None # Should not be None after the or operation
 
511
  sanitized_name = _sanitize_name(name)
512
  schema_hash = _hash_schema(schema)
513
  cache_key = (schema_hash, sanitized_name)
 
449
  ) -> type:
450
  """Create Pydantic BaseModel from object schema with additionalProperties."""
451
  name = name or schema.get("title", "Root")
452
+ if name is None:
453
+ raise ValueError("Name is required")
454
  sanitized_name = _sanitize_name(name)
455
  schema_hash = _hash_schema(schema)
456
  cache_key = (schema_hash, sanitized_name)
 
508
  """Create dataclass from object schema."""
509
  name = name or schema.get("title", "Root")
510
  # Sanitize name for class creation
511
+ if name is None:
512
+ raise ValueError("Name is required")
513
  sanitized_name = _sanitize_name(name)
514
  schema_hash = _hash_schema(schema)
515
  cache_key = (schema_hash, sanitized_name)