version 0.6, SSE changed to http_streamable
This commit is contained in:
parent
4008912401
commit
13c624791d
|
|
@ -14,13 +14,18 @@ from typing import Optional
|
||||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
|
||||||
from mcp.server.fastmcp import FastMCP
|
from mcp.server.fastmcp import FastMCP
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field, AliasChoices
|
||||||
|
|
||||||
from mcp_server.config import load_config
|
from mcp_server.config import load_config
|
||||||
from mcp_server.client import NoteDiscoveryClient
|
from mcp_server.client import NoteDiscoveryClient
|
||||||
|
|
||||||
|
from mcp.server.transport_security import TransportSecuritySettings
|
||||||
|
|
||||||
# Initialize FastMCP server
|
# Initialize FastMCP server
|
||||||
mcp = FastMCP("notediscovery_mcp_http")
|
mcp = FastMCP(
|
||||||
|
"notediscovery_mcp_http",
|
||||||
|
transport_security=TransportSecuritySettings(enable_dns_rebinding_protection=False)
|
||||||
|
)
|
||||||
|
|
||||||
# Load config and client
|
# Load config and client
|
||||||
try:
|
try:
|
||||||
|
|
@ -49,7 +54,7 @@ class ListNotesInput(BaseModel):
|
||||||
offset: int = Field(0, description="Pagination offset")
|
offset: int = Field(0, description="Pagination offset")
|
||||||
|
|
||||||
class PathInput(BaseModel):
|
class PathInput(BaseModel):
|
||||||
path: str = Field(..., description="Note or folder path")
|
path: str = Field(..., validation_alias=AliasChoices('path', 'note', 'name'), description="Note or folder path")
|
||||||
|
|
||||||
class TagInput(BaseModel):
|
class TagInput(BaseModel):
|
||||||
tag: str = Field(..., description="Tag name")
|
tag: str = Field(..., description="Tag name")
|
||||||
|
|
@ -57,21 +62,21 @@ class TagInput(BaseModel):
|
||||||
offset: int = Field(0, description="Pagination offset")
|
offset: int = Field(0, description="Pagination offset")
|
||||||
|
|
||||||
class CreateNoteInput(BaseModel):
|
class CreateNoteInput(BaseModel):
|
||||||
path: str = Field(..., description="Note path")
|
path: str = Field(..., validation_alias=AliasChoices('path', 'note', 'name'), description="Note path")
|
||||||
content: str = Field(..., description="Markdown content")
|
content: str = Field(..., description="Markdown content")
|
||||||
|
|
||||||
class AppendNoteInput(BaseModel):
|
class AppendNoteInput(BaseModel):
|
||||||
path: str = Field(..., description="Note path")
|
path: str = Field(..., validation_alias=AliasChoices('path', 'note', 'name'), description="Note path")
|
||||||
content: str = Field(..., description="Content to append")
|
content: str = Field(..., description="Content to append")
|
||||||
add_timestamp: bool = Field(False, description="Whether to add timestamp")
|
add_timestamp: bool = Field(False, description="Whether to add timestamp")
|
||||||
|
|
||||||
class MoveNoteInput(BaseModel):
|
class MoveNoteInput(BaseModel):
|
||||||
old_path: str = Field(..., description="Current path")
|
old_path: str = Field(..., validation_alias=AliasChoices('old_path', 'old_name', 'old_note', 'source'), description="Current path")
|
||||||
new_path: str = Field(..., description="New path")
|
new_path: str = Field(..., validation_alias=AliasChoices('new_path', 'new_name', 'new_note', 'destination', 'target'), description="New path")
|
||||||
|
|
||||||
class CreateFromTemplateInput(BaseModel):
|
class CreateFromTemplateInput(BaseModel):
|
||||||
template_name: str = Field(..., description="Template name")
|
template_name: str = Field(..., validation_alias=AliasChoices('template_name', 'template', 'name'), description="Template name")
|
||||||
note_path: str = Field(..., description="Note path")
|
note_path: str = Field(..., validation_alias=AliasChoices('note_path', 'path', 'note', 'name'), description="Note path")
|
||||||
|
|
||||||
class GetTemplateInput(BaseModel):
|
class GetTemplateInput(BaseModel):
|
||||||
name: str = Field(..., description="Template name")
|
name: str = Field(..., description="Template name")
|
||||||
|
|
@ -184,7 +189,7 @@ if __name__ == "__main__":
|
||||||
host = os.environ.get("HOST", "0.0.0.0")
|
host = os.environ.get("HOST", "0.0.0.0")
|
||||||
print(f"Starting HTTP streamable MCP server on {host}:{port}", file=sys.stderr)
|
print(f"Starting HTTP streamable MCP server on {host}:{port}", file=sys.stderr)
|
||||||
|
|
||||||
app = mcp.sse_app()
|
app = mcp.streamable_http_app()
|
||||||
from starlette.middleware.cors import CORSMiddleware
|
from starlette.middleware.cors import CORSMiddleware
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue