MCP ExplorerExplorer

Mcp Nim

@lbcheng888on 10 months ago
1 MIT
FreeCommunity
AI Systems
MCP-nim is a Nim SDK for implementing Model Context Protocol for AI agents.

Overview

What is Mcp Nim

mcp-nim is a Nim SDK designed for implementing the Model Context Protocol (MCP) specifically for AI agents, enabling them to manage and utilize contextual information effectively.

Use cases

Use cases for mcp-nim include building AI agents that can read and process files, respond to user queries in a contextual manner, and manage complex interactions across different platforms.

How to use

To use mcp-nim, first install the Nim compiler, then clone the repository and configure the MCP settings according to your environment. You can create MCP servers by defining request handlers and connecting them to the transport layer.

Key features

Key features of mcp-nim include asynchronous request handling, integration with Claude and Cursor applications, and the ability to create custom MCP servers tailored to specific use cases.

Where to use

mcp-nim can be used in various fields such as AI development, chatbot implementation, and any application requiring context-aware AI interactions.

Content

Nim Model Context Protocol (MCP) SDK

Nim implementation of the Model Context Protocol (MCP) for building AI agent capabilities.

Installation

  1. Install Nim compiler
  2. Clone repository:
git clone https://github.com/yourusername/mcp-nim.git
cd mcp-nim

Configuration

Claude Integration

  1. Locate MCP config file:

    • Claude Desktop: ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)
    • Claude Desktop: C:\Users\xxx\AppData\Roaming\Claude\claude_desktop_config.json (Windows)
    • Cursor: %APPDATA%\Cursor\User\globalStorage\rooveterinaryinc.roo-cline\settings\cline_mcp_settings.json (Windows)
  2. Add server configuration:

{
  "mcpServers": {
    "filesystem-server": {
      "command": "nim",
      "args": [
        "c",
        "-r",
        "examples/filesystem_server.nim"
      ],
      "cwd": "/path/to/sdk/root",
      "disabled": false
    }
  }
}

Development

Creating MCP Servers

import std/[asyncdispatch, json, options]
import ../src/mcp/[client, types]
import ../src/mcp/shared/[protocol, stdio, transport]

proc main() {.async.} =
  let transport = newStdioTransport()
  let protocol = newProtocol(some(ProtocolOptions()))
  
  protocol.setRequestHandler(Request, proc(
    request: Request,
    extra: RequestHandlerExtra
  ): Future[McpResult] {.async.} =
    if request.`method` == "your-method":
      result = McpResult()
    else:
      raise newMcpError(ErrorCode.MethodNotFound)
  )

  await protocol.connect(transport)
  await sleepAsync(1000)
  await protocol.close()

when isMainModule:
  waitFor main()

Examples

Filesystem Server

protocol.setRequestHandler("tools/list", proc(request: base_types.JsonRpcRequest, extra: protocol.RequestHandlerExtra): Future[JsonNode] {.async.} =
  result = %*{
    "tools": [
      {
        "name": "read_file",
        "description": "Read file contents",
        "inputSchema": {
          "type": "object",
          "properties": {
            "path": {"type": "string"}
          },
          "required": ["path"],
          "additionalProperties": false
        }
      }
    ]
  }
)

Features

  • Type-safe RPC communication
  • JSON serialization/deserialization
  • Async I/O with progress notifications
  • Capability-based security model
  • Thread-safe implementations

Building

nimble build
nimble test
nimble docs

License

MIT License

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers