使用说明
MCP Reference (F#)
Reference MCP server implemented in F# on ASP.NET Core with:
- official
ModelContextProtocol.AspNetCoremiddleware (/mcp) - SignalR hub (
/hub) for realtime interactions - typed HTTP sample endpoints (
/mcp/echo,/mcp/add) - simple web chat UI (
/) backed by an LLM tool-calling loop (/api/chat)
Requirements
- .NET SDK 9.0+
Quick start
dotnet tool restore
dotnet restore src/mcp_reference.fsproj
dotnet build src/mcp_reference.fsproj -c Debug
dotnet run --project src/mcp_reference.fsproj
Server listens on http://127.0.0.1:5000.
Set OpenAI environment variables for chat:
$env:OPENAI_API_KEY = "<your-key>"
$env:OPENAI_MODEL = "gpt-4.1-mini"
# optional
$env:OPENAI_BASE_URL = "https://api.openai.com/v1/chat/completions"
Endpoints
POST /mcp— official MCP streamable HTTP endpoint (viaMapMcp("/mcp"))GET /— health/home textGET /mcp/tools— local registry tool descriptorsPOST /mcp/tools/{name}— local registry invoke (JSON in, YAML/plain out)POST /mcp/echo— typed sample tool endpoint ({ "Text": "hi" })POST /mcp/add— typed sample tool endpoint ({ "A": 1, "B": 2 })GET/POST /hub— SignalR hub endpointPOST /api/chat— chat endpoint used by home page UI
MCP tools exposed
The official MCP middleware discovers tools from src/Core/McpTools.fs:
Echo(text: string) -> stringAdd(a: int, b: int) -> intListResources() -> string— lists all available MCP resourcesGetResource(uri: string) -> string— retrieves content of a resource by URI
MCP prompts exposed
The official MCP middleware discovers prompts from src/Core/McpPrompts.fs:
Greeting(name: string) -> GetPromptResult— a friendly greeting promptCodeReview(code: string) -> GetPromptResult— a code review prompt
MCP resources exposed
The official MCP middleware discovers resources from src/Core/McpResources.fs:
info://server(text/plain) — general server informationdata://sample(application/json) — a sample JSON data object
Tests
dotnet tool restore
dotnet test tests/mcp_reference.Tests.fsproj -c Debug
Includes integration coverage for root HTTP, typed endpoints, SignalR, and MCP middleware mapping.
MCPInspector quick connect
- Run the server:
dotnet run --project src/mcp_reference.fsproj
- Point MCPInspector to:
http://127.0.0.1:5000/mcp
- Connect and call
tools/list.
Expected: tool list includes Echo and Add.
Notes on dependencies
- Package versions are managed centrally via NuGet Central Package Management in
Directory.Packages.props - Project files reference packages by name only; versions come from that file