Skip to content

Remote MCP and LSP Analysis

SharpMUSH offers two analysis protocols. LSP (Language Server Protocol) supplies editor diagnostics, completion, hover help and argument hints. MCP (Model Context Protocol) lets an AI client request analysis through tools. Neither remote protocol executes softcode, synchronizes attributes or tests gameplay permissions.

ChoiceClient connectionMetadata
Offline language serverEditor starts the local server over standard input/outputLocal analysis without game authentication
Remote LSPEditor starts the stdio bridge; bridge connects over authenticated WSSRefreshed metadata filtered for the authenticated character
Remote MCPMCP client connects over authenticated Streamable HTTPRefreshed metadata filtered for the authenticated character

The remote MCP plugin pins ModelContextProtocol.AspNetCore 2.2.0. That SDK supports MCP revisions 2024-11-05, 2025-03-26, 2025-06-18, 2025-11-25 and 2026-07-28. Clients can pin a supported revision. The 2026-07-28 path uses server/discover and per-request metadata; older revisions use initialize. Default SDK clients prefer 2026-07-28. MCP lifecycle and cancellation belong to the SDK, separate from the LSP dispatcher.

Remote LSP targets a 3.17 capability subset, advertising only implemented capabilities. Its custom sharpmush-lsp-v1 WebSocket transport carries the requests listed below; the bridge adapts ordinary stdio clients to it. It does not implement the whole of LSP 3.17.

This path assumes an already configured HTTPS game and an existing character with a game password. Build the editor and bridge from the same checkout as the server. Analysis uses that character name/password, not the portal account email, a portal cookie, an API key or a GitHub login. Analysis does not save attributes or run commands.

In the repository’s deploy/ directory, add these non-secret switches to .env:

SHARPMUSH_MCP_ENABLED=true
SHARPMUSH_LSP_ENABLED=true

Use only the switches for transports you need. .env supplies Compose interpolation; it does not automatically inject arbitrary entries into a container. deploy/docker-compose.analysis.yml maps these switches to Mcp__Enabled and Lsp__Enabled in sharpmush-server.environment. ASP.NET Core maps double underscores to configuration section separators. Both switches default to false.

# Optional remote analysis; does not publish ports or configure credentials/TLS.
# Use after docker-compose.prod.yml or docker-compose.cloudflare.yml.
services:
sharpmush-server:
environment:
Mcp__Enabled: "${SHARPMUSH_MCP_ENABLED:-false}"
Lsp__Enabled: "${SHARPMUSH_LSP_ENABLED:-false}"
Mcp__Path: /mcp
Lsp__Path: /lsp
Analysis__MaxConcurrentAnalyses: "2"
Analysis__MaxQueuedAnalyses: "8"
Analysis__AnalysisTimeout: "00:00:05"

Validate the merged configuration without starting services (rendered configuration may contain other deployment secrets; do not post it):

Terminal window
cd SharpMUSH/deploy
# If already in deploy/, do not cd again.
docker compose -f docker-compose.prod.yml -f docker-compose.analysis.yml config --quiet

For a reviewed source-built Caddy deployment, the operator applies it with:

Terminal window
docker compose -f docker-compose.prod.yml -f docker-compose.analysis.yml up -d --no-deps --build sharpmush-server

This restarts only the already deployed engine; --no-deps avoids recreating its socket-owner dependencies. The Cloudflare variant uses pulled :dev images instead of a local build. For that already deployed stack, use:

Terminal window
docker compose -f docker-compose.cloudflare.yml -f docker-compose.analysis.yml config --quiet
docker compose -f docker-compose.cloudflare.yml -f docker-compose.analysis.yml pull sharpmush-server
docker compose -f docker-compose.cloudflare.yml -f docker-compose.analysis.yml up -d --no-deps sharpmush-server

Keep the overlay in every subsequent configuration/recreation command, including any configured systemd unit’s Compose invocations. To disable a transport set its switch to false and recreate the server with the same files. Disabled or missing plugins return 404.

The complete optional plugin payloads must remain in plugins/mcp/ and plugins/lsp/; copying only an entry DLL is insufficient. The supplied Caddy route sends /ws to the terminal connection server, while /mcp and /lsp reach the main server through its catch-all route. No extra public port is needed. Use HTTPS for MCP and WSS for LSP, with normally validated certificates. Native clients may omit Origin; if a client sends Origin, its exact HTTP(S) origin needs an AnalysisTransports:AllowedOrigins entry. Do not substitute Cors:AllowedOrigins or wildcard trust.

On the editor machine, install the SDK pinned by the checkout’s global.json, plus Node 22 or newer. From the repository root:

Terminal window
dotnet publish SharpMUSH.LspBridge/SharpMUSH.LspBridge.csproj -c Release -o ./artifacts/lsp-bridge
cd SharpMUSH.LanguageServer/vscode-extension-example
npm ci
npm test
npm run package

Keep the bridge’s entire publish directory. In VS Code’s Extensions menu choose Install from VSIX… and select the generated .vsix.

Open a trusted workspace and set these values in user settings JSON, replacing the path/domain:

{
"sharpmush.languageServer.mode": "remote",
"sharpmush.languageServer.bridgePath": "/absolute/path/SharpMUSH/artifacts/lsp-bridge/SharpMUSH.LspBridge.dll",
"sharpmush.languageServer.endpoint": "wss://mush.example.com/lsp",
"sharpmush.trace.server": "off"
}

Run SharpMUSH: Set Remote Credentials from the Command Palette. Enter the existing character name, then its password in the hidden prompt. The extension stores both in endpoint-bound SecretStorage and injects them only into the bridge child environment. Changing endpoint requires credentials for that endpoint. Use Developer: Reload Window after settings/credential changes, then open or reopen a softcode file. SharpMUSH: Clear Remote Credentials deletes the current endpoint’s entries and stops the client. Never put the password in settings, arguments, URLs, tracing logs or version control.

Create analysis-smoke.mushfn containing add(. Expect a syntax diagnostic in Problems. Replace it with add(1,2); expect that syntax error to clear. Hover add for function help, request completion with ad, and signature help within add(. .mush/.mu use commands per line, .mushfn/.fun use function mode, and .mushcmd uses command-list mode.

An analysis-timeout warning preserves the document; edit again to retry. If pending document work is rejected within an established session, the session closes: reload/reconnect and reopen files. If initial session admission returns HTTP 429 before WebSocket upgrade, no session exists; retry the connection after capacity becomes available. The client does not automatically resume documents.

3. Try MCP with curl before configuring an AI client

Section titled “3. Try MCP with curl before configuring an AI client”

These Bash requests use the named client curl, not an LSP client. Replace the non-secret URL/character. --user has no password argument, so curl prompts on the terminal for the existing character’s password on each request. Do not append :password, use -v/tracing or follow redirects with credentials.

Terminal window
analysis_url=https://mush.example.com/mcp
analysis_character=YourExistingCharacter
curl --silent --show-error --include --user "$analysis_character" \
--header 'Content-Type: application/json' \
--header 'Accept: application/json, text/event-stream' \
--data '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"curl-sharpmush-smoke","version":"1.0"}}}' \
"$analysis_url"

Expect HTTP 200 with JSON-RPC result containing negotiated protocolVersion: "2025-11-25" and tool capabilities. Responses can be JSON or data: records in an SSE response; don’t require one particular envelope rendering. This recipe deliberately pins the tested older initialize lifecycle, not the newer discovery lifecycle.

Terminal window
curl --silent --show-error --include --user "$analysis_character" \
--header 'Content-Type: application/json' \
--header 'Accept: application/json, text/event-stream' \
--header 'MCP-Protocol-Version: 2025-11-25' \
--data '{"jsonrpc":"2.0","method":"notifications/initialized"}' "$analysis_url"
curl --silent --show-error --include --user "$analysis_character" \
--header 'Content-Type: application/json' \
--header 'Accept: application/json, text/event-stream' \
--header 'MCP-Protocol-Version: 2025-11-25' \
--data '{"jsonrpc":"2.0","id":2,"method":"tools/list"}' "$analysis_url"

Expect HTTP 202 without a response body for the notification, then a tool list containing validate, format, hover, complete, signature_help, document_symbols, open_document and close_document. The endpoint is stateless; this recipe does not invent a session-id header.

Terminal window
curl --silent --show-error --include --user "$analysis_character" \
--header 'Content-Type: application/json' \
--header 'Accept: application/json, text/event-stream' \
--header 'MCP-Protocol-Version: 2025-11-25' \
--data '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"validate","arguments":{"code":"add(","parseType":"function"}}}' \
"$analysis_url"

Expect a successful tool result with at least one diagnostic (severity, message, and zero-based start/end line/character fields). Repeat with add(1,2) and expect no syntax diagnostics. Tool results are analysis, not evidence that gameplay permissions or live commands work.

For VS Code’s desktop extension-host MCP client, run MCP: Open User Configuration. Use its VS Code servers/inputs format:

{
"inputs": [{
"id": "sharpmush-basic",
"type": "promptString",
"description": "Base64 of existing character:password (treat as a password)",
"password": true
}],
"servers": {
"sharpmush": {
"type": "http",
"url": "https://mush.example.com/mcp",
"headers": { "Authorization": "Basic ${input:sharpmush-basic}" }
}
}
}

Supply base64 of UTF-8 character:password using trusted local tooling/password management; base64 is reversible and remains a secret. Do not put its value into this file or use an online encoder. This MCP input is separate from the LSP extension’s SecretStorage command. Review server trust, start it using MCP: List Servers, then ask the agent to call validate with code: "add(", parseType: "function"; confirm the tool invocation and inspect the diagnostic. This needs an available VS Code chat/agent provider. Interactive-input configurations are not forwarded to Agent Host sessions; this example is scoped to the desktop extension host. No OAuth/browser-ticket login is offered by SharpMUSH.

Client configuration fields follow the VS Code MCP reference; VS Code setup guidance describes user configuration and trust.

SymptomCheck
/mcp or /lsp returns 404Enabled flag actually appears in the server environment; matching image/plugin payload; correct route and overlay on recreation
401Existing character name/password, not portal account email; account/character active state; changed password; proxy preserves Authorization
403 with OriginExact AnalysisTransports:AllowedOrigins value; native clients may omit Origin
MCP GET returns 405Expected when no SSE stream is available; use POST initialize/tool requests, not a browser GET health test
400 or unsupported MCP methodProtocol revision/lifecycle, Content-Type and Accept headers; do not combine discovery with older initialization
408 / 413 / 429Body-read deadline, size cap or admission/IP limit; reduce input/retry later; proxy may impose a smaller cap
LSP fails before diagnosticsWSS URL, valid TLS chain, /lsp main-server routing and sharpmush-lsp-v1 transport via bridge; /ws is terminal only
VS Code does not start bridgeTrusted workspace, installed VSIX, existing bridge DLL/dependencies, dotnet on PATH, mode/endpoint and stored credentials; reload window
Diagnostic warning analysis-timeoutNext edit retries; no document reopening needed just for this warning
Initial LSP HTTP 429No session was opened; retry the connection when capacity is available
Established-session overload closeReconnect, initialize and reopen current text; no transparent resume

Keep the analysis quotas, authentication and exact Origin policy described in the remote-analysis contract. Do not disable certificate validation to make a failing client connect.

Publish SharpMUSH.Server normally. Shipped optional plugins are plugins/mcp/ and plugins/lsp/. Keep each complete directory (entry DLL, manifest, dependency manifest and private SDK closure). Both modules are boot-time and independently removable/disabled; configuration defaults to false. An operator enables only the chosen transport by setting its Enabled value to true and restarting the host. The example below shows the disabled defaults. Removing/disabling a module or setting Enabled=false yields 404 at its reserved path, not SPA HTML.

{
"Mcp": { "Enabled": false, "Path": "/mcp" },
"Lsp": { "Enabled": false, "Path": "/lsp" },
"Analysis": { "MaxConcurrentAnalyses": 2, "MaxQueuedAnalyses": 8, "AnalysisTimeout": "00:00:05" },
"AnalysisTransports": { "AllowedOrigins": [] }
}

Host MushBasic authenticates character name/password. Host MushAnalysis policy requires that scheme and validates any Origin against the exact HTTP(S) allowlist. No Origin is required for native clients; provided Origin is denied by default. No wildcard/request-Host-derived origin trust. The IP limiter runs before named authorization, including rejected credentials. Character incarnation, account ownership/active state and password version are refreshed before analysis. Analysis and metadata never execute code or expose attribute values.

Analysis:* governs one cooperative work pool shared by both transports. Mcp:MaxConcurrentAnalyses, Mcp:MaxQueuedAnalyses and Mcp:AnalysisTimeout are fallback values; Analysis:* overrides them. Deadlines include queue time and metadata resolution. Work retains its slot until actual termination; these are cooperative deadlines, not hard preemption.

MCP is stateless Streamable HTTP at /mcp, with eight tools: validate, format, hover, complete, signature_help, document_symbols, open_document, close_document. Intelligence uses refreshed principal-filtered metadata. Filtered command hover preserves command locks, including for aliases. Owner-local functions are not exposed as ordinary global calls. The MCP limits section below describes byte, document, idle-time and HTTP caps. Enabled GET without an SSE stream returns authenticated 405.

Endpoint wss://<game>/lsp requires host authentication/Origin policy before upgrade. Subprotocol sharpmush-lsp-v1 uses one UTF-8 JSON-RPC object per WebSocket text message, no batching. It is a custom transport for LSP; use the stdio bridge for ordinary LSP clients. /ws remains the terminal.

First features: initialize/shutdown/exit, full-document didOpen/didChange/didClose, diagnostics, completion, hover, signature help, cancellation. Positions are UTF-16. File extensions: .mush, .mu (commands per line), .mushfn, .fun (function), .mushcmd (command list). No remote formatting/rename/definitions/references, attribute synchronization, execution, server filesystem reads or transparent session/document resume. Older document versions cannot replace newer ones, and stale analysis cannot publish into a newer or closed document. Independent sessions remain isolated even with the same principal and URI. Metadata is refreshed per analysis operation.

Lsp settingDefault
MaxDocumentBytes5,242,880 UTF-8 bytes
MaxMessageBytes33,554,432 raw JSON bytes
MaxResponseBytes1,048,576 raw JSON bytes
MaxSessions16
MaxSessionsPerPrincipal2
MaxDocumentsPerSession8
MaxBytesPerSession33,554,432 UTF-8 bytes
MaxStoredBytes134,217,728 UTF-8 bytes across LSP sessions
MaxPendingRequests8 per session
MaxConcurrentReaders2 globally
MessageReadTimeout00:00:10
IdleTimeout00:05:00
SessionTimeout00:15:00

Limits account text/envelopes, not actual heap usage. Oversize/malformed frames or exceeded session quotas terminate/reject the operation explicitly. Cancellation/control messages bypass work queues. Disconnect, idle/session deadline and host stop cancel work and release documents; uncooperative workers still retain their execution admission until termination. Responses have bounded result counts.

MaxConcurrentReaders bounds fragmented messages with growing buffers. Quiet clients and small single-frame control messages bypass those reader slots. If synchronization diagnostics cannot be admitted under overload, the server explicitly closes the connection rather than retaining the newest text without analysis. After an explicit close, reconnect, initialize a fresh session and reopen documents; there is no automatic document resume. A per-analysis diagnostics deadline is different: it publishes a generation-checked warning with code analysis-timeout, preserves usable session/document state and retries on the next edit. A timeout alone does not require reopening the document.

The editor side, the SharpMUSH.LspBridge stdio bridge, is in Softcode in Your Editor.

The optional SharpMUSH.Plugins.Mcp plugin owns this state and transport. The host supplies authentication/authorization and the analyzer. open_document returns an opaque id, close_document returns a boolean, and analysis accepts inline code or a document id.

Handles belong to the authenticated MushBasic identity’s character key, creation time and optional account id. Identity comes from the current HTTP request, not a tool parameter. A different character/incarnation/account cannot read or close a handle. Foreign handles behave like unknown handles. Missing or different authentication schemes cannot access the store. This does not change which credentials the endpoint accepts or grant game writes.

Configure these keys under the Mcp section:

KeyDefaultMeaning
MaxDocumentBytes5,242,880UTF-8 bytes of stored or inline code, before analysis
MaxDocumentsPerPrincipal64Open handles for one authenticated identity
MaxBytesPerPrincipal33,554,432Total UTF-8 text bytes for that identity
MaxStoredDocuments1,024Global open handle cap
MaxStoredBytes134,217,728Global UTF-8 text budget
DocumentIdleTimeout00:15:00Idle timeout; successful owner reads renew it
MaxRequestBodyBytes33,554,432Raw HTTP envelope before JSON decoding
MaxConcurrentRequests4Global admitted HTTP requests; no waiting queue
BodyReadTimeout00:00:10Elapsed deadline for buffering a POST body
MaxConcurrentAnalyses2Global analysis workers
MaxQueuedAnalyses8Additional admitted analyses waiting for a worker
AnalysisTimeout00:00:05Elapsed analysis budget including queue time

All budgets and the timeout must be positive. The aggregate defaults allow multiple full 5 MiB documents. Counts and byte accounting are atomic under concurrent opens/closes. Admission rejects new work when any budget is full instead of evicting another user. Close or idle expiry releases budget. Foreign reads do not refresh idle time. Expiry is checked on store operations; idle entries may remain allocated until a later operation, but remain subject to the global caps.

These are UTF-8 text accounting limits, not measured managed-heap limits. Strings, parser structures, JSON bodies and protocol overhead consume more memory. An endpoint wrapper bounds declared and unknown-length POST bodies before SDK JSON decoding. Authorized requests spool beyond a 64 KiB prefix into request-owned temporary storage. Oversize bodies return 413, full HTTP admission 429, and slow body reads 408. Client/host-stop/disposal cancellation interrupts body reads, and admission resources remain until actual handlers finish. Authentication runs before body admission; the IP limiter runs before named Basic authorization so failed authentication is also limited. Host Origin policy requires an exact AnalysisTransports:AllowedOrigins entry when a header is present; native clients may omit Origin. The endpoint sets Kestrel’s mutable body-size feature to the configured envelope limit, preserving other routes’ limits. A proxy or a body-size feature already made read-only can impose a lower cap. The 32 MiB default accepts a 5 MiB ASCII document even when every character is escaped as six JSON bytes, with protocol overhead. Temporary storage and parser memory remain distinct from text quotas.

The six analysis tools acquire a global worker with an elapsed deadline and request cancellation. Ambient shorter execution budgets remain effective. Saturated admission returns a tool error. Cancellation reaches syntax lexing, token buffering, tree/line traversal and intelligence loops; analysis propagates cancellation instead of disguising it as diagnostics or unchanged output. The executor awaits actual worker termination before releasing capacity, including after timeout or host shutdown. This is cooperative cancellation, not hard preemption: an uncooperative library call can overrun its deadline, while retaining its worker and admission slots until it ends. Open/close remain synchronous and document-only. Cancellation tokens are injected by the SDK and do not appear in the tool schemas.

Over-budget input returns a tool error, and idle handles expire after DocumentIdleTimeout. Handles last only as long as the process and are lost on restart. No tool takes a principal or owner argument.

Even successful analysis cannot establish that a command works in a game or that permissions are correct. Review changes and test them under the intended gameplay identity separately.

For the local language server and editor setup, see Softcode in Your Editor. For plugin authoring, see Writing Plugins.