home / mcp / nextjs mcp server

Nextjs MCP Server

MCP server + client API to make MCP enabled LLM requests with Vercel AI SDK (headless). Next.js implementation of "mcp-use"

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "cameronking4-nextjs-mcp-use": {
      "url": "http://localhost:3002/sse",
      "headers": {
        "API_KEY": "your-api-key"
      }
    }
  }
}

You can run a headless MCP setup that routes requests to multiple MCP servers using a configurable registry. This lets you enable or disable servers, pass per-server environment variables, and test endpoints from a single place.

How to use

Use a central MCP registry to configure and route to MCP servers. You can enable multiple servers, supply per-server environment variables, and test endpoints from a single setup. The registry stores server definitions and controls how you access each MCP server via HTTP.

Key endpoints you’ll work with in this setup are the streaming Chat API and the non-streaming Completions API. You can test these endpoints to ensure your MCP routing is working as expected.

Testing lets you verify behavior with default and custom URLs, ensuring your MCP adapters are reachable and returning the expected responses.

Example registry entries show how to enable an MCP server and provide per-server credentials. You can copy the structure and adjust URLs and keys to match your environment.

How to install

Prerequisites: you need Node.js and npm installed on your machine. Optionally, for advanced deployment you may use GitHub Actions for automated testing and monitoring.

Follow these steps to set up the registry locally and prepare for running the MCP server adapter.

1) Create the registry configuration file that defines your MCP servers and their environment variables.

{
  "server-name": {
    "url": "http://localhost:3002/sse",
    "enabled": true,
    "env": {
      "API_KEY": "your-api-key"
    }
  },
  "another-server": {
    "url": "https://example.com/sse",
    "enabled": false
  }
}

Additional notes

Environment variables can be configured per MCP server. These variables are loaded when the server is initialized and can be used to authenticate requests or customize behavior per server.

Testing scripts are available to verify the chat and completions endpoints. Use the provided commands to invoke each endpoint with a message.

# Test the chat endpoint
npm run test:chat -- --message "Your message here"

# Test the completions endpoint
npm run test:completions -- --message "Your message here"

# Test with a custom URL
npm run test:chat -- --url http://localhost:3000/api/chat --message "Your message here"

Available tools

chat_endpoint

Streaming chat endpoint exposed at /api/chat for real-time chat interactions via MCP routing.

completions_endpoint

Non-streaming completions endpoint exposed at /api/completions for standard text generation via MCP routing.

test_client

Sample client usage to invoke MCP endpoints for validation and experimentation.