# Build Custom MCP Servers (/tutorials/mcp-servers/custom-mcp-servers)

Build your own custom MCP servers



## When to Build Custom MCP Servers

Build custom MCP servers when:

* Native servers don't exist for your specific APIs
* You need custom business logic beyond what existing servers provide
* You have proprietary systems that require custom integration

If pre-built servers meet your needs, consider [Native MCP servers](/tutorials/mcp-servers/native-mcp-servers), [Composio's platform](/tutorials/mcp-servers/composio-mcp-servers), or [Gram](/tutorials/mcp-servers/gram) instead.

## Getting Started

The Quick Start workspace includes a Next.js app in the `apps/mcp/app/` directory that you can use to expose your MCP servers.
Each MCP server you create will be exposed on a separate route on this app.

#### Creating from a template

You can add a custom MCP server template from our [template library](https://github.com/inkeep/agents/tree/main/agents-cookbook/template-mcps) for common use cases using the [CLI](/typescript-sdk/cli-reference#inkeep-add).

```bash
inkeep add --mcp [server-name]
```

This will automatically add a custom MCP server template to your Quick Start workspace. After customizing and deploying it, you can register it.

#### Using Vercel's Template

If you want to create a custom MCP server, you can use Vercel's [Next.js MCP template](https://vercel.com/templates/next.js/model-context-protocol-mcp-with-next-js) as a starting point:

<Steps>
  <Step>
    From the workspace root, add the Vercel template:

    ```bash
    inkeep add --mcp vercel-template
    ```
  </Step>

  <Step>
    Rename the template to your desired server name:

    ```bash
    mv apps/mcp/app/vercel-template apps/mcp/app/[server-name]
    ```
  </Step>

  <Step>
    Update the `basePath` inside `apps/mcp/app/[server-name]/mcp/route.ts` to `/[server-name]`:

    ```typescript
    {
      basePath: "/[server-name]",
      verboseLogs: true,
      maxDuration: 60,
      disableSse: true,
    }
    ```
  </Step>

  <Step>
    Customize the template with your desired tools.
  </Step>

  <Step>
    You can access the server at `http://localhost:3006/[server-name]/mcp`. Register it with your agents using the `mcpTool` function.

    ```typescript
    import { mcpTool } from '@inkeep/agents-sdk';

    export const mcpTool = mcpTool({
      id: '[server-name]',
      name: '[server-name]',
      description: '[server-name] API',
      serverUrl: 'http://localhost:3006/[server-name]/mcp',
    });
    ```

    Or you register the MCP server as a tool in the Visual Builder (see [here](/visual-builder/tools/mcp-servers#register-an-mcp-server)).
  </Step>
</Steps>

#### Deploying to Vercel

Follow the instructions in [Deploy to Vercel](/self-hosting/vercel#step-9-create-a-vercel-project-for-your-mcp-server-optional).
If you have already deployed to Vercel, you can simply update the deployment by pushing to the same repository.

<Note>
  Enable Fluid compute and set `maxDuration` to 800 in `apps/mcp/app/[server-name]/[transport]/route.ts` if you're on a Pro or Enterprise plan and have long-running operations.
</Note>

<>
  ### Next steps

  Once you have your server, you can register it in one of:

  <Cards>
    <Card title="The TypeScript SDK" icon="LuCode" href="/typescript-sdk/tools/mcp-tools#step-2-register-the-mcp-server-as-a-tool-in-your-agent">
      Add your MCP server as a tool for your agents in the TypeScript SDK
    </Card>

    <Card title="The Visual Builder" icon="LuPalette" href="/visual-builder/tools/mcp-servers#register-an-mcp-server">
      Add your MCP server as a tool for your agents in the Visual Builder
    </Card>
  </Cards>
</>