MCP service and telemetry
The MCP service gives Model Context Protocol clients read-only access to decoded Solana account and transaction data. It joins a guarded /mcp route with a stateless MCP handler, a client documentation page, reachability status, and optional usage telemetry. It is the MCP-specific integration surface described in integration surfaces, alongside the HTTP controls documented in HTTP API and feature controls.
Service boundary
The MCP route is the public boundary for protocol requests. It accepts the MCP transport methods over Streamable HTTP and keeps the route outside the /api/* space so MCP traffic does not pass through the BotID proxy matcher. The service is disabled unless MCP_ENDPOINT_ENABLED is true.
The route applies checks before it loads the MCP package or runs a tool request:
- A client IP in
MCP_BLOCKED_IPSreceives403 Forbidden. - A disabled endpoint receives
503 MCP endpoint is disabled. - When
MCP_ACCESS_KEYShas values, the request needs a matchingAuthorization: Bearer <key>header and otherwise receives401 Unauthorized. - When
MCP_ACCESS_KEYSis unset, the service allows open access and logs a startup warning. OPTIONSreturns the CORS contract. Successful responses and JSON errors carry the same CORS headers.
The route returns a controlled 500 Internal error when handler construction or request processing fails. It also reports the failure to Sentry so a protocol or server fault does not appear as an unexplained client error.
References: app/…/route.ts• L9-90 app/…/README.md• L1-6
Request lifecycle
The request lifecycle moves from deployment checks to dependency-backed tool handling and then to response cleanup. A client first negotiates MCP with initialize, then lists or calls tools with the protocol version selected by that handshake.
This diagram shows the main path for an authorized client request.
sequenceDiagram
participant C as MCP client
participant R as /mcp route
participant H as MCP handler
participant S as MCP server
participant D as Solana data services
C->>R: OPTIONS or POST /mcp
R->>R: Check IP, enabled flag, and bearer key
R->>H: Load shared handler
H->>S: Create a fresh server and transport
C->>S: initialize
S-->>C: Negotiated protocol and server identity
C->>S: tools/list or tools/call
S->>D: Read account or transaction data
D-->>S: On-chain data and enrichments
S-->>C: JSON MCP result
H->>H: Close transport and server
The handler uses a fresh server and transport for each request. This makes the service stateless and suitable for serverless execution. The handler closes both resources after the response, while close failures are logged without replacing an already produced response.
References: packages/…/handler.ts• L14-62 packages/…/handler.integration.spec.ts• L50-88 packages/…/handler.integration.spec.ts• L375-398
Startup and dependency construction
The service builds its MCP dependencies on the first enabled request. Lazy loading keeps a disabled endpoint inert and avoids loading the MCP package when the route cannot serve traffic. The handler import is cached for later requests, but a failed import clears that cache so a temporary startup fault does not persist until redeploy. The dependency module is server-only because it reads key-bearing RPC settings.
Startup construction combines host-app services with the entity inspector package:
| Dependency | Service role |
|---|---|
| Enabled cluster list | Defines the networks the tool advertises and accepts. |
| RPC endpoints | Gives each supported network a data source. Dedicated MCP URLs take priority over the app's server RPC settings. |
| Program name lookup | Adds the Explorer's known program labels. |
| Instruction fallback | Lets transaction results use the Explorer's supported instruction decoders when package decoders do not resolve an instruction. |
| Logger | Sends package diagnostics through the app logger. |
| Sentry wrapper | Adds server-side error and span reporting around tool work. |
| Telemetry sink | Sends optional MCP usage events after tool handling. |
The enabled cluster list is an explicit opt-in set. It currently includes mainnet-beta, devnet, and testnet. The handler checks that every enabled cluster has a valid RPC endpoint before it starts serving. This prevents a client from seeing a network in the tool schema that the service cannot query. RPC URLs are resolved at handler initialization so key-bearing values come from runtime configuration rather than a build artifact. Every supported cluster has an endpoint entry, including clusters that are not enabled.
The instruction fallback also keeps decoded transaction data safe for the MCP wire format. It adapts the app's registered instruction parsers and converts values such as bigint into JSON-safe values. The dependency tests cover registered Pyth instructions, product attributes, Ed25519 offsets, and zk-ElGamal proof context, while confirming that unsupported programs remain unresolved.
References: app/…/dependencies.ts• L1-97 app/…/dependencies.spec.ts• L1-151 app/…/mcp-clusters.ts• L1-6 packages/…/handler.ts• L21-56 packages/…/config.ts• L1-13
Tool surface
Two tools form the MCP surface. inspect_entity is the product feature and declares read-only, idempotent behavior. ping is the small health contract used by clients that need an end-to-end protocol check.
| Tool | Purpose | Main input or result |
|---|---|---|
inspect_entity | Reads a Solana account address or transaction signature and returns a structured entity. | A base58 identifier and an optional enabled cluster. It can return token, program, system-account, compressed NFT, and transaction data with available IDL or bundled decoding. |
ping | Confirms that the MCP endpoint and tool contract work. | No input. Returns pong. |
The tools do not sign, submit, or mutate blockchain data. The default cluster is mainnet-beta when that network is enabled. If a deployment uses another enabled set, the first enabled cluster becomes the default.
References: packages/…/server.ts• L11-38 packages/…/server.ts• L81-138 app/…/ToolsShowcase.tsx• L13-20 app/…/ToolsShowcase.tsx• L85-175 packages/…/config.ts• L6-13
Client documentation experience
The /mcp/start page introduces the service and helps an engineer or coding agent connect a supported client. The server page delegates to a client-side overview that shows the deployment endpoint, transport, authentication state, enabled clusters, tools, setup instructions, agent guidance, and example questions.
The setup area provides copyable instructions for Claude Code, Cursor, Windsurf, Codex, and VS Code. Each snippet uses the current deployment origin and the shared solana-explorer server name. An open deployment needs no key. When the page detects a gated endpoint, the snippets include an Authorization header placeholder and show the file-based setup needed by clients whose quick-add UI cannot set headers.
The page also provides an agent instruction block that tells agents to use inspect_entity for on-chain facts and to report errors or unknown fields instead of guessing. Tool panels explain the read-only contract and supported inputs. Example conversations show how agents can inspect token mints, programs, transactions, and Token-2022 extensions.
References: app/…/page.tsx• L1-12 app/…/page-client.tsx• L1-7 app/…/McpDocsOverviewView.tsx• L30-217 app/…/setup-clients.ts• L13-136 app/…/ToolsShowcase.tsx• L48-175 app/…/ExamplesCarousel.tsx• L102-261
Health probe
The /mcp/start status display uses a lightweight GET /mcp reachability probe rather than a full MCP ping call. A non-5xx response means that the route is reachable even when the request lacks the POST method and MCP headers required for a real client session.
The probe runs after the page loads and records response time. It maps the result to a small status model:
| Status | Meaning |
|---|---|
checking | The browser has not completed the probe. |
ready | The route answered without a server error. |
restricted | The route returned 401, so an access key is required. |
blocked | The route returned 403, so the visitor's IP is not allowed. |
disabled | The route returned a 5xx response or the request failed. |
This check tells the visitor whether the copied open or restricted setup can work on the current deployment. It does not replace a client handshake or validate the full tool response.
References: app/…/McpDocsOverviewView.tsx• L21-58 app/…/EndpointStatus.tsx• L1-67 app/…/useDeploymentOrigin.ts• L5-17
Usage telemetry
MCP telemetry is an optional server-side usage stream. The app creates a GA4 provider only when it has both MCP_GA_API_SECRET and either MCP_GA_MEASUREMENT_ID or the shared NEXT_PUBLIC_GOOGLE_ANALYTICS_ID; otherwise tracking is a no-op with one startup warning.
The service records two event types:
mcp_initializerecords a completed MCP handshake.mcp_tool_callrecords the tool name, duration, success or error status, and available result context such as cluster, entity kind, decode source, and error code.
The MCP server invokes tool tracking after a handler returns. The app delivers the event through Next's after() hook. A failed provider or client-id lookup is logged and reported to Sentry without changing the tool result. The event builder does not include the caller's identifier in the event fields.
The GA4 client ID uses a hashed session ID when the request has mcp-session-id. If no session exists, it uses a hash of the first forwarded client IP. If neither exists, it uses anon. These values are pseudonyms rather than anonymous identifiers, so event counts are more reliable than user counts for service analysis.
References: app/…/telemetry.ts• L11-63 packages/…/server.ts• L40-60 packages/…/server.ts• L89-99 packages/…/analytics-event.ts• L49-74 packages/…/TELEMETRY.md• L3-50
Test coverage
The tests protect the service contracts at three levels. Route tests verify the deployment gate, IP block, bearer-key behavior, open-access warning, CORS behavior, and controlled errors. Package integration tests exercise real MCP transport negotiation, tool listing, ping, error results, injected telemetry, server wrapping, and cleanup.
The inspect_entity unit tests verify input validation, account and transaction payloads, partial source failures, instruction and account decoding, entity classification, and enrichment fallbacks. The host dependency tests verify that app instruction parsers produce JSON-safe fallback payloads for supported instruction families and return no fallback for unsupported programs. The telemetry tests verify provider activation rules, measurement-ID fallback, client-ID precedence and hashing, anonymous fallback, and failure isolation. Together these tests protect the boundaries between client protocol traffic, host configuration, data services, the client documentation contract, and analytics.
References: app/…/route.spec.ts• L26-123 app/…/route.open-access.spec.ts• L19-43 app/…/dependencies.spec.ts• L47-151 packages/…/handler.integration.spec.ts• L90-206 packages/…/handler.integration.spec.ts• L218-372 packages/…/inspect-entity.spec.ts• L75-211 packages/…/inspect-entity.spec.ts• L228-379 packages/…/inspect-entity.spec.ts• L497-725 app/…/telemetry.spec.ts• L33-173
Change checklist
When these files or sections are changed, remember to consider these:
- Keep
MCP_ENABLED_CLUSTER_NAMES, the tool's accepted cluster enum, its default cluster, and the documentation page cluster text aligned. - Keep the route's auth and CORS behavior aligned with client setup snippets and with preview Deployment Protection requirements.
- Keep the documentation probe's status mapping aligned with the route's
401,403, and5xxresponses. A reachable route does not prove that an MCP handshake or tool call will succeed. - Keep event names within the
mcp_prefix and GA4 length limit. Register new event parameters in the GA4 property before relying on them in reports. - Keep client-ID precedence and hashing rules free of raw session tokens and IP addresses.
- If an RPC environment name or enabled cluster changes, update the endpoint resolution and the handler's startup validation together.
- Keep the tool's advertised read-only contract and its error guard aligned with the result and telemetry wrappers.
- Keep each client setup snippet's auth form aligned with the client's ability to pass HTTP headers.
- Keep app instruction parser output JSON-safe before exposing it through transaction results. A parser that returns unsupported wire values can break the MCP response instead of only losing one decode.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
MCP_ENDPOINT_ENABLED is false or missing | Clients receive 503 and no MCP package is loaded. | Enable the route at deploy time and check the documentation page status. |
MCP_ACCESS_KEYS is set but the client omits or sends a wrong bearer key | The request receives 401 before handler construction. | Add the exact bearer key to the client configuration. |
MCP_ACCESS_KEYS is unset in a protected deployment | The route is open and logs a startup warning. | Set access keys or use an upstream access control layer. |
| An enabled cluster has no resolved or valid RPC endpoint | Handler construction fails before tool calls can run. | Provide a dedicated MCP RPC URL or the app's fallback RPC setting for every enabled cluster. |
| An instruction parser returns a value that cannot cross JSON serialization | A transaction result can fail during fallback decoding even though the source instruction is valid. | Convert parser values to JSON-safe numbers or strings and keep unsupported programs unresolved. |
| An identifier is malformed, oversized, or not a supported cluster value | inspect_entity returns INVALID_ARGUMENT without a valid entity lookup. | Validate the base58 identifier and use an enabled cluster. |
The documentation page sees 401 or 403 but the client setup cannot carry the required header | The copied setup cannot connect even though the route is reachable. | Use the client-specific config-file form and replace <access-key>. |
A client treats a successful bare GET /mcp as a completed MCP session | The client may still fail when it sends the real MCP request. | Use the status display only as a reachability check and verify the client connection. |
| GA4 measurement ID or API secret is missing | Usage analytics stays disabled while MCP calls continue. | Supply both server telemetry credentials and confirm the startup warning is absent. |
| Telemetry delivery or client-ID lookup fails | The event is lost and the failure is logged or sent to Sentry; the MCP result still succeeds. | Treat telemetry as best-effort and monitor its error signal separately from tool availability. |
Key files
| File | Why to read it |
|---|---|
| app/…/route.ts | Defines the public route gate, authentication, IP block, CORS, and failure response. |
| app/…/dependencies.ts | Shows how the app assembles the package handler and host-specific data services. |
| app/…/dependencies.spec.ts | Shows the JSON-safe instruction fallback contract for supported and unsupported instruction data. |
| packages/…/handler.ts | Explains the stateless MCP request lifecycle and dependency validation. |
| packages/…/server.ts | Defines the tool surface, read-only behavior, error isolation, and tracking hooks. |
| app/…/page.tsx | Provides the /mcp/start entry point and page metadata. |
| app/…/page-client.tsx | Connects the route page to the client documentation overview. |
| app/…/McpDocsOverviewView.tsx | Shows the documentation flow from endpoint status to setup, agent instructions, tools, and examples. |
| app/…/setup-clients.ts | Defines client setup forms, gated-deployment auth guidance, and agent instructions. |
| app/…/EndpointStatus.tsx | Defines the status shown for reachable, restricted, blocked, and disabled deployments. |
| app/…/telemetry.ts | Connects MCP events to optional GA4 delivery and pseudonymous client IDs. |
| packages/…/analytics-event.ts | Defines the high-level shape of tool usage events. |
| packages/…/TELEMETRY.md | Documents event meaning, GA4 fields, and the limits of client-based reporting. |
| packages/…/handler.integration.spec.ts | Demonstrates the real MCP handshake, tool calls, telemetry, and cleanup contract. |
| packages/…/inspect-entity.spec.ts | Shows the entity lookup result contract and how source or enrichment faults degrade. |