A Next.js implementation of the Model Context Protocol (MCP) server with a frontend interface for interacting with MCP tools.
- MCP server implementation using the
@modelcontextprotocol/sdk
- Two client options:
- Standard MCP Client (uses Redis for communication)
- Direct API Client (bypasses Redis for more reliable testing)
- Sample tools: echo, time, calculate
- Redis connection status monitoring
Update app/mcp.ts
with your tools, prompts, and resources following the MCP TypeScript SDK documentation.
-
Install dependencies:
pnpm install
-
Set up a Redis instance:
# Start Redis locally redis-server # Or configure a cloud Redis URL in .env echo "REDIS_URL=your_redis_url_here" > .env.local
-
Start the development server:
pnpm dev
-
Open http://localhost:3000 to access the frontend interface.
- Uses the full MCP protocol with Redis for communication
- Requires a working Redis connection
- Access at http://localhost:3000/mcp-client
- Bypasses Redis and calls the MCP tools directly via API
- More reliable for testing but doesn't use the full MCP protocol
- Access at http://localhost:3000/direct-client
If you're experiencing timeout issues with the standard MCP client:
- Make sure Redis is running locally (
redis-server
) - Check the Redis connection status on the home page
- Try the Direct API Client instead which bypasses Redis
- Check server logs for detailed error information
- Consider using a cloud Redis provider like Upstash
- Requires a Redis attached to the project under
process.env.REDIS_URL
- Make sure you have Fluid compute enabled for efficient execution
- After enabling Fluid compute, open
app/sse/route.ts
and adjust max duration to 800 if you using a Vercel Pro or Enterprise account - Deploy the Next.js MCP template
script/test-client.mjs
contains a sample client to try invocations via command line.
node scripts/test-client.mjs https://mcp-for-next-js.vercel.app
# mcp-with-monad