mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-19 14:54:24 +01:00
Update URL validation to allow file and other nonstandard schemas
This commit is contained in:
@@ -2,7 +2,7 @@ import anyio
|
||||
import click
|
||||
import mcp.types as types
|
||||
from mcp.server.lowlevel import Server
|
||||
from pydantic import AnyUrl
|
||||
from pydantic import FileUrl
|
||||
|
||||
SAMPLE_RESOURCES = {
|
||||
"greeting": "Hello! This is a sample text resource.",
|
||||
@@ -26,7 +26,7 @@ def main(port: int, transport: str) -> int:
|
||||
async def list_resources() -> list[types.Resource]:
|
||||
return [
|
||||
types.Resource(
|
||||
uri=AnyUrl(f"file:///{name}.txt"),
|
||||
uri=FileUrl(f"file:///{name}.txt"),
|
||||
name=name,
|
||||
description=f"A sample text resource named {name}",
|
||||
mimeType="text/plain",
|
||||
@@ -35,8 +35,7 @@ def main(port: int, transport: str) -> int:
|
||||
]
|
||||
|
||||
@app.read_resource()
|
||||
async def read_resource(uri: AnyUrl) -> str | bytes:
|
||||
assert uri.path is not None
|
||||
async def read_resource(uri: FileUrl) -> str | bytes:
|
||||
name = uri.path.replace(".txt", "").lstrip("/")
|
||||
|
||||
if name not in SAMPLE_RESOURCES:
|
||||
|
||||
Reference in New Issue
Block a user