refactor: replace mcp.types as types to from mcp import types (#1986)
This commit is contained in:
parent
4fc49c62bd
commit
1a8c14a5b8
1 changed files with 66 additions and 73 deletions
22
README.md
22
README.md
|
|
@ -682,7 +682,7 @@ The Context object provides the following capabilities:
|
|||
- `ctx.session` - Access to the underlying session for advanced communication (see [Session Properties and Methods](#session-properties-and-methods))
|
||||
- `ctx.request_context` - Access to request-specific data and lifespan resources (see [Request Context Properties](#request-context-properties))
|
||||
- `await ctx.debug(message)` - Send debug log message
|
||||
- `await ctx.info(message)` - Send info log message
|
||||
- `await ctx.info(message)` - Send info log message
|
||||
- `await ctx.warning(message)` - Send warning log message
|
||||
- `await ctx.error(message)` - Send error log message
|
||||
- `await ctx.log(level, message, logger_name=None)` - Send log with custom level
|
||||
|
|
@ -1110,13 +1110,13 @@ The session object accessible via `ctx.session` provides advanced control over c
|
|||
async def notify_data_update(resource_uri: str, ctx: Context) -> str:
|
||||
"""Update data and notify clients of the change."""
|
||||
# Perform data update logic here
|
||||
|
||||
|
||||
# Notify clients that this specific resource changed
|
||||
await ctx.session.send_resource_updated(AnyUrl(resource_uri))
|
||||
|
||||
|
||||
# If this affects the overall resource list, notify about that too
|
||||
await ctx.session.send_resource_list_changed()
|
||||
|
||||
|
||||
return f"Updated {resource_uri} and notified clients"
|
||||
```
|
||||
|
||||
|
|
@ -1145,11 +1145,11 @@ def query_with_config(query: str, ctx: Context) -> str:
|
|||
"""Execute a query using shared database and configuration."""
|
||||
# Access typed lifespan context
|
||||
app_ctx: AppContext = ctx.request_context.lifespan_context
|
||||
|
||||
|
||||
# Use shared resources
|
||||
connection = app_ctx.db
|
||||
settings = app_ctx.config
|
||||
|
||||
|
||||
# Execute query with configuration
|
||||
result = connection.execute(query, timeout=settings.query_timeout)
|
||||
return str(result)
|
||||
|
|
@ -1644,7 +1644,7 @@ from contextlib import asynccontextmanager
|
|||
from typing import Any
|
||||
|
||||
import mcp.server.stdio
|
||||
import mcp.types as types
|
||||
from mcp import types
|
||||
from mcp.server.lowlevel import NotificationOptions, Server
|
||||
from mcp.server.models import InitializationOptions
|
||||
|
||||
|
|
@ -1758,7 +1758,7 @@ uv run examples/snippets/servers/lowlevel/basic.py
|
|||
import asyncio
|
||||
|
||||
import mcp.server.stdio
|
||||
import mcp.types as types
|
||||
from mcp import types
|
||||
from mcp.server.lowlevel import NotificationOptions, Server
|
||||
from mcp.server.models import InitializationOptions
|
||||
|
||||
|
|
@ -1837,7 +1837,7 @@ import asyncio
|
|||
from typing import Any
|
||||
|
||||
import mcp.server.stdio
|
||||
import mcp.types as types
|
||||
from mcp import types
|
||||
from mcp.server.lowlevel import NotificationOptions, Server
|
||||
from mcp.server.models import InitializationOptions
|
||||
|
||||
|
|
@ -1939,7 +1939,7 @@ import asyncio
|
|||
from typing import Any
|
||||
|
||||
import mcp.server.stdio
|
||||
import mcp.types as types
|
||||
from mcp import types
|
||||
from mcp.server.lowlevel import NotificationOptions, Server
|
||||
from mcp.server.models import InitializationOptions
|
||||
|
||||
|
|
@ -2012,7 +2012,7 @@ For servers that need to handle large datasets, the low-level server provides pa
|
|||
```python
|
||||
"""Example of implementing pagination with MCP server decorators."""
|
||||
|
||||
import mcp.types as types
|
||||
from mcp import types
|
||||
from mcp.server.lowlevel import Server
|
||||
|
||||
# Initialize the server
|
||||
|
|
|
|||
Loading…
Reference in a new issue