MCP (Model Context Protocol)

The MCP plugin enables AI clients (Claude, Cursor, etc.) to interact with your Nimbus application through tools, resources, and prompts. Inspired by Laravel's MCP.

Try the MCP demo — a weather server with tools and resources you can connect from Cursor or Claude Desktop.

Installation

Add the plugin and register a server in bin/server.go:

import (
    "github.com/CodeSyncr/nimbus"
    nimbusmcp "github.com/CodeSyncr/nimbus/plugins/mcp"
)

func main() {
    app := nimbus.New()

    mcpPlugin := nimbusmcp.New()
    mcpPlugin.Web("/mcp/weather", myWeatherServer)
    app.Use(mcpPlugin)

    // ...
}

Use the nimbusmcp alias to avoid conflict with github.com/mark3labs/mcp-go/mcp.

Set MCP_PREFIX to prepend all mounted MCP routes (for example, /internal turns /mcp/weather into /internal/mcp/weather).

Creating a Server

Create an MCP server with tools, resources, and prompts:

import (
    "context"
    "fmt"
    nimbusmcp "github.com/CodeSyncr/nimbus/plugins/mcp"
    "github.com/mark3labs/mcp-go/mcp"
)

var myWeatherServer = nimbusmcp.NewServer("Weather Server", "1.0.0",
    nimbusmcp.WithInstructions("Provides weather info."),
)

func init() {
    myWeatherServer.AddTool(
        mcp.NewTool("get_weather",
            mcp.WithDescription("Get weather for a location"),
            mcp.WithString("location", mcp.Required()),
        ),
        handleGetWeather,
    )
}

func handleGetWeather(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
    location, _ := req.RequireString("location")
    return mcp.NewToolResultText(fmt.Sprintf("Sunny, 72°F in %s", location)), nil
}

Tools

Tools let AI clients perform actions. Define with mcp.NewTool:

mcp.NewTool("calculate",
    mcp.WithDescription("Perform arithmetic"),
    mcp.WithString("operation", mcp.Required(), mcp.Enum("add", "subtract")),
    mcp.WithNumber("x", mcp.Required()),
    mcp.WithNumber("y", mcp.Required()),
)

Resources

Resources expose data. Use NewResourceTemplate for dynamic URIs:

mcp.NewResourceTemplate("weather://forecast/{location}", "Forecast",
    mcp.WithTemplateDescription("Weather for a location"),
    mcp.WithTemplateMIMEType("application/json"),
)

Prompts

Prompts provide reusable prompt templates:

mcp.Prompt{
    Name:        "describe-weather",
    Description: "Generate a weather description",
    Arguments: []mcp.PromptArgument{
        {Name: "location", Description: "City name", Required: true},
    },
}

Connecting from Cursor

Add the MCP server in Cursor settings. For a server at /mcp/weather on localhost (default port 3333):

{
  "mcpServers": {
    "nimbus-weather": {
      "url": "http://localhost:3333/mcp/weather"
    }
  }
}

If MCP_PREFIX is set, include it in the URL (for example http://localhost:3333/internal/mcp/weather).

Transport

Uses Streamable HTTP (MCP spec): POST for JSON-RPC, GET for SSE. Compatible with Cursor, Claude Desktop, and other MCP clients.

Related

For text generation and agents, see AI SDK.