echo tool to a slate, deploy it, and call it from a Model Context Protocol (MCP) client. The tool accepts a string and returns it as text. You can optionally attach a View that renders inside an MCP Apps-compatible client.
Start from an existing slate checkout. Each tool lives in a directory under mcp/, and the hosted slate serves its tools at /mcp. The local development server does not serve that endpoint, so you will test the tool after deployment.
MCP tools cannot use resources yet. An MCP declaration’s
connections, databases and secrets must be empty, and the build fails otherwise. Resource execution is implemented only for the app and agents.Add a tool
Create the tool's declaration
Create
mcp/echo/ and add a declaration next to the tool’s code. It uses the same schema as the app’s public/slate.json. This tool requires no resources:mcp/echo/slate.json
Write the tool
mcp/<name>/index.ts exports two things. tool is the native MCP tool definition, with a Zod inputSchema and an optional Zod outputSchema. handler runs each call and returns an MCP tool result.mcp/echo/index.ts
inputSchema before it calls handler. The starter’s workers/app.ts already passes every mcp/*/index.ts module to createSlateWorker; keep that wiring.Build and deploy
pnpm build runs the MCP build along with the app’s, so it reports a declaration or definition error before you push. Commit and push main to deploy; see Deploy.Connect an MCP client
The slate’s MCP endpoint ishttps://<name>.contextlayer.xyz/mcp. Replace <name> with the hosted slate name printed by init. ContextLayer registers this endpoint as an OAuth-protected resource when it creates the slate; you do not need to create a separate OAuth application for it.
Add the endpoint to your client
Add
https://<name>.contextlayer.xyz/mcp to your MCP client as a remote server.Sign in and approve the client
Follow the client’s OAuth sign-in flow, sign in with your ContextLayer account, and approve access. If a coding agent is setting up the client, a person completes this browser approval.The client discovers the authorization server through the slate’s OAuth resource metadata. ContextLayer identifies clients through their Client ID Metadata Document; this discovery is handled by the client.
Use the tools
Confirm that the client lists The result should contain the text
echo, then call it with:Hello from my slate. If you attached a View and the client supports MCP Apps, it can also display that View.The client’s token is issued for this slate’s /mcp endpoint with the mcp:access scope. It does not authorize another slate or the platform management API./mcp. The slate’s viewing rule still applies: a private slate admits its owning user and members of its owning organization.
Attach a View, if the tool needs one
The text-only tool above is complete without a View. To display an interface inside a compatible MCP client, add an HTML entry point atmcp-ui/echo/index.html:
mcp-ui/echo/index.html
tool definition:
What the SDK builds
During the build, the SDK’s Vite integration evaluates eachmcp/<name>/index.ts, validates its slate.json, and converts its Zod schemas to JSON Schema. It writes the tools and Views into a generated /mcp.json manifest among the slate’s assets. It compiles each View into one HTML file with its scripts and styles inlined.
ContextLayer reads the deployed manifest to list the slate’s tools and serve its Views. Tool discovery does not import your authored modules. Each actual tool call runs your handler in the slate’s Worker.