# MCP server

Give Agents the tools of your app. Write one file for each tool, and connect the Agent to /mcp.

```ts [server/mcp/tools/add.ts]
import { defineMcpTool } from 'vite-hub/mcp'
import { z } from 'zod'

// The file name is the tool name: add
export default defineMcpTool({
  description: 'Add two numbers.',
  input: z.object({ a: z.number(), b: z.number() }),
  handler: ({ a, b }) => ({ sum: a + b }),
})
```

```bash [terminal]
# Connect Claude Code to the server of your app
claude mcp add --transport http my-app https://app.example.com/mcp

# List the tools that the build found
vitehub inspect definitions --kind mcp-tool
```

### [One file is one tool](https://vitehub.dev/docs/mcp/get-started#write-a-tool)

Each file in `server/mcp/tools/` is one tool. The file name is the tool name.

### [Arguments are checked](https://vitehub.dev/docs/mcp/server-api#define-a-tool)

`input` is a Standard Schema, such as Zod or Valibot. The server checks the arguments before the handler runs.

### [Sign in with MCP OAuth](https://vitehub.dev/docs/mcp/configure#sign-in-with-mcp-oauth)

With Auth, the server needs an access token. The handler knows the user and the client.

### [No MCP SDK](https://vitehub.dev/docs/mcp/limits-and-errors#protocol)

ViteHub's own stateless Streamable HTTP server. It keeps no session between requests.

### [Prompts and resources](https://vitehub.dev/docs/mcp/server-api#define-a-prompt)

Each file in `server/mcp/prompts/` is one prompt, and each file in `server/mcp/resources/` is one resource.

### [Inspect the tools](https://vitehub.dev/docs/mcp/get-started#inspect-the-tools)

`vitehub inspect definitions --kind mcp-tool` lists the tools that the build found.

Use the MCP server when the app must give its own tools to Agents. Install `@vite-hub/mcp`, set `auth` and `mcp: true` in the ViteHub options, add `mcpOAuth()` from `vite-hub/auth/mcp` to `server/auth.ts`, and add one `defineMcpTool()` default export for each file in `server/mcp/tools/`. Import it from `vite-hub/mcp`. Add prompts with `defineMcpPrompt()` in `server/mcp/prompts/` and resources with `defineMcpResource()` in `server/mcp/resources/`. Set `mcp.instructions` and `mcp.serverInfo` to name the server.

`mcp: true` without `auth` fails the build with `VITE_HUB_MCP_AUTH_MISSING`. Set `mcp: { auth: false }` only when anyone may call every tool.

Use `defineMcpHooks()` in `server/mcp.ts` to map the caller to the app's own user and to log tool calls.

This is not the ViteHub MCP of the Console at `https://console.vitehub.dev/mcp`. Do not add an MCP SDK. Throw an error with a 4xx `status` to tell the Agent what to fix.

Prove it with `vitehub inspect definitions --kind mcp-tool`, then with a real `tools/list` and `tools/call` request to `/mcp`.

<!-- vitehub-docs:section-links -->
## In this section

- [Overview](https://vitehub.dev/raw/docs/mcp.md) (this page)
- [Get started](https://vitehub.dev/raw/docs/mcp/get-started.md)
- [Configure](https://vitehub.dev/raw/docs/mcp/configure.md)
- [Server API](https://vitehub.dev/raw/docs/mcp/server-api.md)
- [Limits and errors](https://vitehub.dev/raw/docs/mcp/limits-and-errors.md)

Next: [MCP_R0001](https://vitehub.dev/raw/docs/mcp/diagnostics/mcp_r0001.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
