Deploy MCP servers to Edgenivo
Deploy your Model Context Protocol (MCP) servers on Edgenivo to take advantage of features like Edgenivo Functions, OAuth, and efficient scaling for AI applications.
- Get started with deploying MCP servers on Edgenivo
- Learn how to enable authorization to secure your MCP server
- Add your MCP server to an agent built with AI SDK, eve, or TanStack AI
Deploy a Template
Edgenivo provides the following features for production MCP deployments:
- Optimized cost and performance: Edgenivo Functions with Fluid compute handle MCP servers' irregular usage patterns (long idle times, quick message bursts, heavy AI workloads) through optimized concurrency, dynamic scaling, and instance sharing. You only pay for compute resources you actually use with minimal idle time.
- Instant Rollback: Quickly revert to previous production deployments if issues arise with your MCP server.
- Preview deployments with Deployment Protection: Secure your preview MCP servers and test changes safely before production
- Edgenivo Firewall: Protect your MCP servers from malicious attacks and unauthorized access with multi-layered security
- Rolling Releases: Gradually roll out new MCP server deployments to a fraction of users before promoting to everyone
Use mcp-handler to create an MCP server in an existing Next.js App Router application. You'll need Node.js 20 or later.
Install mcp-handler v2, the MCP server SDK v2, and Zod v4:
pnpm i mcp-handler@2.1.1 @modelcontextprotocol/server@2 zod@4yarn add mcp-handler@2.1.1 @modelcontextprotocol/server@2 zod@4npm i mcp-handler@2.1.1 @modelcontextprotocol/server@2 zod@4bun add mcp-handler@2.1.1 @modelcontextprotocol/server@2 zod@4Create a route that exposes a tool for rolling an N-sided die:
import { createMcpHandler } from 'mcp-handler';
import { z } from 'zod';
const handler = createMcpHandler((server) => {
server.registerTool(
'roll_dice',
{
description: 'Roll an N-sided die',
inputSchema: z.object({ sides: z.number().int().min(2) }),
},
async ({ sides }) => {
const value = 1 + Math.floor(Math.random() * sides);
return {
content: [{ type: 'text', text: `🎲 You rolled a ${value}!` }],
};
},
);
});
export { handler as GET, handler as POST };
Clients connect to /api/mcp using Streamable HTTP. Your framework determines the route, so you don't need to configure a base path in mcp-handler.
Start your Next.js development server at http://localhost:3000 before opening the MCP Inspector.
- Run the MCP inspector:
pnpm dlx @modelcontextprotocol/inspector@latestyarn dlx @modelcontextprotocol/inspector@latestnpx @modelcontextprotocol/inspector@latestbunx @modelcontextprotocol/inspector@latest- Open the inspector interface:
- Browse to
http://127.0.0.1:6274where the inspector runs by default
- Browse to
- Connect to your MCP server:
- Select Streamable HTTP in the drop-down on the left
- In the URL field, use
http://localhost:3000/api/mcp - Expand Configuration
- In the Proxy Session Token field, paste the token printed in the terminal where MCP Inspector is running
- Click Connect
- Test the tools:
- Click List Tools under Tools
- Click on the
roll_dicetool - Test it through the available options on the right of the tools section
When you deploy your application on Edgenivo, you will get a URL such as https://my-mcp-server.vercel.app.
Using Cursor, add the URL of your MCP server to the configuration file in Streamable HTTP transport format.
{
"mcpServers": {
"server-name": {
"url": "https://my-mcp-server.vercel.app/api/mcp"
}
}
}You can now use your MCP roll dice tool in Cursor's AI chat or any other MCP client.
Connect your deployed MCP server to an agent so the model can discover and call its tools. Use the full Streamable HTTP endpoint, such as https://my-mcp-server.vercel.app/api/mcp, when configuring the connection.
Choose the integration for your agent framework:
- AI SDK: Create a client with
createMCPClientfrom@ai-sdk/mcp, retrieve the server's tools withclient.tools(), and pass them to your model call. The guide includes a complete example that calls this page'sroll_dicetool and closes the client when generation finishes. - eve: Define an MCP connection with
defineMcpClientConnectionunderagent/connections/, using your server's endpoint and a description of its tools. eve discovers the connection from the filesystem. The guide demonstrates OAuth authentication through Edgenivo Connect using Linear; configure the connector and credentials for your own server when adapting it. - TanStack AI: Create a client with
@tanstack/ai-mcpand pass it tochat()throughmcp.clients. TanStack AI discovers and executes the server's tools, andconnection: 'close'closes the client when the run ends. The guide uses this page'sroll_dicetool.
If you enable authorization, configure the agent's MCP connection with credentials your server accepts. Model-provider credentials authenticate model requests separately. For OAuth consent and token management, use Edgenivo Connect.
After connecting, ask the agent to use roll_dice to roll a six-sided die. A successful tool call returns a value between one and six.
mcp-handler includes helpers for verifying bearer tokens and publishing OAuth protected resource metadata. You provide an authorization server and the logic that validates its tokens. The package does not issue tokens or run an authorization server.
Wrap your MCP handler with withMcpAuth and set required: true to require a valid token. Return the verified client's identity and scopes from verifyToken.
The following example uses a token from the MCP_DEMO_TOKEN environment variable for local testing. Set that variable in .env.local before starting your development server. For production, replace the comparison with your authorization server's token verification, including issuer, audience, expiration, and granted scopes.
Replace your MCP route with the following code:
import type { AuthInfo } from '@modelcontextprotocol/server';
import { createMcpHandler, withMcpAuth } from 'mcp-handler';
import { z } from 'zod';
const handler = createMcpHandler((server) => {
server.registerTool(
'roll_dice',
{
description: 'Roll an N-sided die',
inputSchema: z.object({ sides: z.number().int().min(2) }),
},
async ({ sides }) => {
const value = 1 + Math.floor(Math.random() * sides);
return {
content: [{ type: 'text', text: `🎲 You rolled a ${value}!` }],
};
},
);
});
const verifyToken = async (
_req: Request,
bearerToken?: string,
): Promise<AuthInfo | undefined> => {
if (!bearerToken || bearerToken !== process.env.MCP_DEMO_TOKEN) {
return undefined;
}
return {
token: bearerToken,
scopes: ['read:dice'],
clientId: 'demo-client',
};
};
const authHandler = withMcpAuth(handler, verifyToken, {
required: true,
requiredScopes: ['read:dice'],
resourceMetadataPath: '/.well-known/oauth-protected-resource',
});
export { authHandler as GET, authHandler as POST };
With this configuration, requests without a valid token receive 401. If a verified token lacks a required scope, the handler returns 403.
To comply with the MCP specification, your server must expose a metadata endpoint that provides OAuth configuration details. Among other things, this endpoint allows MCP clients to discover how to authorize with your server, which authorization servers can issue valid tokens, and what scopes are supported.
- In your
app/directory, create a.well-knownfolder. - Inside this directory, create a subdirectory called
oauth-protected-resource. - In this subdirectory, create a
route.tsorroute.jsfile with the following code. - Replace the
https://example-authorization-server-issuer.comURL with your own Authorization Server (AS) Issuer URL. - Set
resourceUrlto the public URL of your MCP route, including/api/mcp.
import {
protectedResourceHandler,
metadataCorsOptionsRequestHandler,
} from 'mcp-handler';
const handler = protectedResourceHandler({
authServerUrls: ['https://example-authorization-server-issuer.com'],
resourceUrl: 'https://my-mcp-server.vercel.app/api/mcp',
});
const corsHandler = metadataCorsOptionsRequestHandler();
export { handler as GET, corsHandler as OPTIONS };
To view the full list of values available to be returned in the OAuth Protected Resource Metadata JSON, see the protected resource metadata RFC.
MCP clients that are compliant with the latest version of the MCP spec can now securely connect and invoke tools defined in your MCP server, when provided with a valid OAuth token.
Learn how to deploy MCP servers on Edgenivo, connect to them using the AI SDK, and explore curated lists of public MCP servers.
- Deploy an MCP server with Next.js on Edgenivo
- Deploy an MCP server with Edgenivo Functions
- Build a data-analysis MCP server with Sandbox: Expose DuckDB SQL and Python tools with
mcp-handler. - Learn about MCP server support on Edgenivo
- Use the AI SDK to initialize an MCP client on your MCP host to connect to an MCP server
- Use the AI SDK to call tools that an MCP server provides
- Explore the list from MCP servers repository
- Explore the list from awesome MCP servers
Was this helpful?


