MCP协议管理器

Posuer是一个强大的模型上下文协议(MCP)管理器,通过容器化、动态配置重载和多服务器聚合等功能增强大型语言模型的能力。

  • by jkoelker
  • Go
  • 本地部署
  • 4 星标
  • 更新于
在 GitHub 查看 jkoelker/posuer

使用说明

Posuer:MCP经理和中间人

一个强大的模型上下文协议(MCP)管理器,通过以下方式增强大型语言模型:

  • Docker容器化 -在具有自动检测功能的隔离容器中运行MCP服务器
  • 动态配置重新加载 -无需重新启动即可更新服务器配置
  • 多服务器聚合 -整合来自不同服务器的工具和资源
  • 智能能力路由 -将请求直接发送到适当的后端服务器
  • 高级配置 -对刀具暴露的精细控制

项目愿景

Posuer充当MCP客户端(如Claude Desktop)和多个客户端之间的桥梁 MCP服务器。而不是将每个服务器单独连接到LLM 客户,Posuer让您:

  1. 整合多台服务器 -通过单个连接点管理所有MCP服务器
  2. 聚合能力 -整合来自不同服务器的工具、资源和提示
  3. 简化配置 -使用单个YAML文件定义所有服务器连接
  4. 提高可靠性 -监控服务器运行状况并妥善处理故障

运作原理

┌───────────────┐                  ┌──────────────────────────────────────┐
│               │                  │                                      │
│   LLM Client  │◄─── MCP/stdio ──►│               Posuer                 │
│ (Claude, etc) │                  │                                      │
│               │                  │                                      │
└───────────────┘                  └──┬─────────────┬─────────────┬───────┘
                                      │             │             │
                                  MCP/stdio     MCP/stdio     MCP/SSE
                                      │             │             │
                                      ▼             ▼             ▼
                                 ┌─────────┐   ┌─────────┐   ┌─────────┐
                                 │ ServerA │   │ ServerB │   │ ServerC │
                                 └─────────┘   └─────────┘   └─────────┘

Posuer实现了MCP协议的两个方面:

  • 它作为一个 MCP服务器 对于像Claude Desktop这样的客户
  • 它作为一个 MCP客户端 到后端服务器
  • 它根据功能在它们之间智能地路由消息

主要特点

  • 动态服务器管理 -配置和管理多个MCP服务器
  • 能力聚合 -整合来自所有服务器的资源、工具和提示
  • 智能路由 -将请求直接发送到相应的后端服务器
  • 多种运输方式 -支持stdio和SSE连接
  • 配置包含 -包括来自多个文件的服务器配置,包括Claude Desktop配置
  • 错误处理 -妥善处理服务器故障
  • 日志记录 -调试和监控的详细日志

安装

先决条件

  • 达到1.23或更高
  • 访问MCP服务器(例如,文件系统、天气、搜索等)

从源头构建

# Clone the repository
git clone https://github.com/jkoelker/posuer.git
cd posuer

# Build the binary
make

# The binary will be created in the build directory
ls -la build/posuer

用法

# Run with default configuration (config.yaml)
./build/posuer

# Run with a specific configuration file
./build/posuer -config /path/to/config.yaml

# Show version information
./build/posuer -version

# Run in stdio mode (default)
./build/posuer -stdio

# Run with config file watcher enabled
./build/posuer -config /path/to/config.yaml -watch

配置

Posuer是使用YAML文件配置的。默认情况下,它会查找 config.yaml 在以下位置(按顺序):

  1. 由指定的路径 -config 旗帜
  2. 用户配置目录(例如。, ~/.config/posuer/config.yaml)

配置示例:

# Posuer configuration file
servers:
  # Direct server definition
  - name: filesystem
    type: stdio
    command: npx
    args:
      - -y
      - "@modelcontextprotocol/server-filesystem"
      - "/tmp"

  # You can also include other config files
  - ~/other-servers.yaml
  - ~/.config/Claude/claude_desktop_config.json

  # Example of an SSE server (remote)
  - name: remote-server
    type: sse
    url: https://example.com/sse

能力配置选项

Posuer提供灵活的能力配置,有三种格式:

  1. 布尔值(启用/禁用整个服务器)

    servers:
      - name: all-enabled
        type: stdio
        command: npx
        args:
          - -y
          - "@modelcontextprotocol/server-memory"
        enable: true  # Enable all capabilities
    
      - name: all-disabled
        type: stdio
        command: npx
        args:
          - -y
          - "@modelcontextprotocol/server-memory"
        enable: false  # Disable all capabilities (or use disable: true)
    
  2. 列表(工具的快速格式)

    servers:
      - name: specific-tools
        type: stdio
        command: npx
        args:
          - -y
          - "@modelcontextprotocol/server-memory"
        enable:
          - create_entities  # Only enable these specific tools
          - read_graph
    
      - name: blocked-tools
        type: stdio
        command: npx
        args:
          - -y
          - "@modelcontextprotocol/server-filesystem"
          - "/tmp"
        disable:
          - write_file  # Disable these specific tools
          - move_file
    
  3. 地图(高级功能过滤)

    servers:
      - name: advanced-filtering
        type: stdio
        command: npx
        args:
          - -y
          - "@modelcontextprotocol/server-memory"
        enable:
          tools:  # Enable specific tools
            - create_entities
            - read_graph
          prompts: system_prompt  # Enable a single prompt
          templates:  # Enable specific templates
            - entity_template
            - graph_template
        disable:
          tools:  # Disable specific tools (even if in enable list)
            - delete_entities
    

地图格式支持按不同功能类型进行过滤:

  • tools:LLM可以调用的工具函数
  • prompts:LLM可以使用的系统提示
  • templates:动态内容的资源模板
  • resources:静态资源(文件等)

查看默认配置 pkg/config/config.yaml 了解更多详细信息 配置示例。

动态配置重新加载

Posuer支持动态配置重新加载,允许您修改 服务运行时的配置文件。检测到变化 自动应用,无需重新启动。

要启用此功能,请使用 -watch 标志:

# Run with configuration file watching enabled
./posuer -config /path/to/config.yaml -watch

修改配置文件时:

  1. Posuer自动检测到变化
  2. 加载并验证新配置
  3. 添加新服务器,更新现有服务器,关闭删除的服务器
  4. 在不中断活动连接的情况下应用所有更改

此功能适用于:

  • 动态添加新的MCP服务器
  • 在不重新启动Posuer的情况下删除或禁用服务器
  • 在开发过程中测试不同的配置
  • 在生产中旋转API键或更新端点

文件观察器包括去抖动功能,以防止在快速编辑过程中过度重新加载。

配置选项

  • servers:要包含的服务器配置或文件路径数组
    • 对于直接服务器定义:
      • name:服务器名称(用于命名空间功能)
      • type:服务器连接类型(“stdio”或“sse”)
      • command:要运行的命令(用于stdio)
      • args:命令行参数
      • env:环境变量
      • url服务器 URL( 对于 sse 类型)
      • enable:启用特定功能(请参阅下面的格式选项)
      • disable:禁用特定功能(请参阅下面的格式选项)
      • container:容器配置(请参阅下面的容器选项)
    • 对于文件包含,只需以字符串形式提供文件路径

容器配置

Posuer支持在容器中运行MCP服务器,以改善隔离和依赖关系管理。容器配置可以以三种格式指定:

  1. 简单格式:只需将图像名称指定为字符串

    servers:
      - name: filesystem
        type: stdio
        command: npx
        args:
          - -y
          - "@modelcontextprotocol/server-filesystem"
          - "/tmp"
        container: "node:18-alpine"
    
  2. 完整架构:指定一个包含所有容器选项的映射

    servers:
      - name: database
        type: stdio
        command: npx
        args:
          - -y
          - "@modelcontextprotocol/server-sqlite"
        container:
          image: node:18-alpine
          volumes:
            "/data": "/app/data"
          env:
            DB_PATH: "/app/data/database.sqlite"
          network: host
          workdir: "/app"
          args:
            - "--cap-add=SYS_ADMIN"
    
  3. 明确禁用:设置为false可禁用容器隔离,包括自动检测

    servers:
      - name: no-container
        type: stdio
        command: npx  # Would normally use a container automatically
        args:
          - -y
          - "@modelcontextprotocol/server-filesystem"
          - "/tmp"
        container: false  # Explicitly disable container usage
    

容器配置选项:

  • image:要使用的容器映像(必需)
  • volumes:主机路径到容器路径的映射
  • env:传递给容器的环境变量
  • network:网络模式(主机、网桥等)
  • user:用户在容器中运行
  • workdir:容器中的工作目录
  • args:传递给容器运行时的其他参数

集装箱自动检测

Posuer可以自动检测某些命令,并在适当的容器中运行它们:

  • npx 命令会自动在中运行 docker.io/node:alpine
  • uvx 命令会自动在中运行 ghcr.io/astral-sh/uv:alpine

使用常见的Node.js和Python包管理器时,这种自动检测简化了配置。例如:

servers:
  # This will automatically run in a Node.js container
  - name: filesystem
    type: stdio
    command: npx
    args:
      - -y
      - "@modelcontextprotocol/server-filesystem"
      - "/tmp"
    # No container configuration needed, it will be auto-detected

  # To explicitly disable container detection
  - name: local-npm
    type: stdio
    command: npx
    args:
      - -y
      - some-local-package
    container: false  # Explicitly disable container detection

Posuer将自动检测系统上是否有容器运行时(podman或docker),并首选podman以获得更好的无根容器支持。

与Claude Desktop集成

要将Posuer与Claude Desktop一起使用:

  1. 如上所述建造Posuer
  2. 使用所需的MCP服务器创建配置文件
  3. 更新您的Claude Desktop配置,将Posuer用作MCP服务器:
{
  "mcpServers": {
    "posuer": {
      "command": "/path/to/posuer",
      "args": ["-watch"]
    }
  }
}
  1. 重新启动克劳德桌面

发展

# Format code
make fmt

# Run linter
make lint

# Run tests
make test

# Clean build artifacts
make clean

许可证

此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。