AI代理服务器

一个集成了OpenAI和Anthropic的AI代理服务器,提供自然语言处理、多步规划、智能推理和自主任务执行功能。

  • by BenBoBenBo
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 benbobenbo/mcp-server

使用说明

🤖 代理AI MCP服务器

一个老练的 模型上下文协议(MCP)服务器 由...驱动 真正的人工智能能力该服务器提供自然语言处理、多步骤规划、智能推理和自主任务执行 OpenAI和Anthropic集成.

✨ 特性

🧠 真正的人工智能能力

  • 🤖 OpenAI集成:GPT-4o、GPT-4o-mini、GPT-3.5涡轮增压支持
  • 🧠 人类整合:克劳德3(俳句、十四行诗、歌剧)支持
  • 🔄 智能回退:如果需要,可以优雅地模仿人工智能
  • 💰 成本优化:最佳性价比的推荐型号
  • 🔐 安全:基于环境的API密钥管理

🎯 智能功能

  • 自然语言理解:用真正的人工智能实现真正的理解
  • 多步骤规划:自动任务分解和执行
  • 自主推理:情境感知决策
  • 记忆与语境:持续的对话历史
  • 智能合成:结合多种工具的连贯响应

🔧 智能工具

  • AI助手:由真实人工智能驱动的自然语言界面
  • 智能文件分析:具有AI洞察力的深度代码/文本分析
  • 天气规划师:基于条件的智能活动建议
  • 时间智能:基于上下文的时间和日期响应
  • 文件操作:增强了人工智能驱动的洞察力

🚀 快速开始

1.安装

npm install

2.配置Real AI(推荐)

npm run setup-ai               # Interactive AI setup wizard

或 手动创建 .env 使用API密钥(请参阅 AI设置指南)

3.启动服务器

npm start                      # Start with real AI capabilities
npm run client              # Launch universal interactive client
npm run demo                # Try the demo mode

🎯 建筑

该服务器具有针对AI功能优化的干净、生产就绪的架构:

src/
├── core/                   # 🧠 Shared AI Components
│   ├── memory.js          # Memory management system
│   ├── ai-agent.js        # AI reasoning and planning engine  
│   └── tools.js           # Shared tool definitions and execution
├── clients/               # � Smart Client Applications
│   └── universal.js       # Universal agentic AI client
└── index.js               # 🤖 Main agentic AI server

tests/                     # 🧪 Comprehensive Test Suite
├── agentic.test.js        # AI capabilities testing
└── integration.test.js    # End-to-end validation

examples/                  # 📚 Usage Examples & Demos
└── simple-client.js       # Basic client implementation

🔄 架构优势

  • 📦 模块化设计:共享核心组件消除了代码重复
  • 🧹 清洁结构:服务器、客户端、测试、示例的逻辑分离
  • ⚡ 优化性能:延迟加载、内存管理、结果缓存
  • 🔧 更好的可维护性:人工智能逻辑和工具的单一真实来源
  • 🧪 综合测试:具有集成覆盖的专用测试套件
  • 📚 清晰的示例:不同用例的重点示例

📖 使用示例

自然语言接口

// Ask the AI assistant anything!
await client.callTool("ai_assistant", {
  request: "Analyze my TypeScript project and suggest architectural improvements",
  session_id: "my_session"
});

await client.callTool("ai_assistant", {
  request: "Help me organize these files using best practices",
  session_id: "my_session"
});

智能文件分析

await client.callTool("smart_file_analysis", {
  path: "package.json",
  analysis_type: "all"  // summary, structure, quality, security, all
});

基于天气的规划

await client.callTool("weather_planner", {
  city: "London",
  activity_type: "outdoor"  // outdoor, indoor, mixed
});

🧠 AI智能功能

多步骤规划

AI会自动创建执行计划:

  1. 请求分析:了解你想要实现的目标
  2. 工具选择:为每个步骤选择最佳工具
  3. 执行:以最佳顺序运行工具
  4. 合成:将结果组合成智能响应

规划流程示例

User: "Analyze my project and suggest improvements"

AI Reasoning: "User wants project analysis. I should read files, analyze structure, and provide insights."

Execution Plan:
1. list_files (get project structure)
2. read_file (analyze key files like package.json)
3. ai_analyze_content (provide intelligent insights)

Result: Comprehensive analysis with specific recommendations

记忆与语境

  • 基于会话的内存:记住你的对话
  • 语境意识:了解您的项目和偏好
  • 学习:根据您的互动改进响应

🔧 可用工具

🤖 AI驱动的工具

工具 说明 示例用法
ai_assistant 用于复杂任务的自然语言界面 “帮助我重构此代码”
smart_file_analysis 基于AI的文件分析,具有洞察力 分析代码质量、结构、安全性
weather_planner 基于天气的活动规划 获取任何城市的活动建议

📁 文件操作

工具 说明
read_file 使用AI分析读取文件内容
write_file 将内容写入文件
list_files 使用智能分类列出目录内容
get_weather 基本天气信息

📚 AI资源

访问高级AI功能:

  • ai://conversation-history -你的对话记忆
  • ai://capabilities -完整的AI功能文档
  • ai://reasoning-engine -人工智能如何做出决策
  • weather://cities -可用的天气位置

🎯 示例用例

项目分析

"Analyze my Node.js project structure and suggest improvements"
→ AI reads files, analyzes dependencies, suggests organization

天气规划

"Plan outdoor activities in Paris considering current weather"
→ AI checks weather, suggests appropriate activities with explanations

代码审查

"Review my TypeScript code for potential issues"
→ AI analyzes code quality, security, and best practices

文件组织

"Help me organize my project files using industry standards"
→ AI analyzes structure, suggests reorganization with reasoning

🛠️ 发展

可用命令(新架构)

# 🚀 Server Management
npm start                    # Start optimized agentic AI server
npm run start:traditional   # Start traditional TypeScript server
npm run dev                 # Development mode - traditional server
npm run dev:agentic         # Development mode - AI server

# 👥 Client Applications  
npm run client              # Universal auto-detecting client
npm run client:simple       # Basic example client
npm run demo                # Interactive demonstration

# 🧪 Testing & Validation
npm test                    # Test traditional server
npm run test:agentic        # Test AI capabilities  
npm run test:integration    # Test server switching
npm run test:all            # Run complete test suite

# 🔧 Development Tools
npm run build               # Build TypeScript components
npm run clean               # Remove redundant files (architectural cleanup)

服务器架构

  • agentic-server.js:主AI驱动服务器
  • src/index.ts:传统MCP服务器(TypeScript)
  • 存储器系统:对话和上下文管理
  • AI 代理:规划和推理引擎
  • 工具编排:智能多工具工作流程

🤝 整合

VS代码扩展

在中配置 .vscode/mcp.json:

{
  "agentic-ai-server": {
    "command": "node",
    "args": ["agentic-server.js"],
    "description": "Agentic AI MCP Server with natural language processing"
  }
}

客户端开发

const client = new Client({
  name: "my-agentic-client",
  version: "1.0.0"
});

// Connect to agentic server
const transport = new StdioClientTransport({
  command: "node",
  args: ["agentic-server.js"]
});

await client.connect(transport);

// Use natural language!
const result = await client.callTool("ai_assistant", {
  request: "What can you help me with?",
  session_id: "my_app"
});

📦 依赖项

核心MCP

  • @modelcontextprotocol/sdk -MCP协议实现
  • zod -架构验证

人工智能能力

  • openai -OpenAI API集成(可选)
  • @anthropic-ai/sdk -Anthropic API集成(可选)
  • uuid -会话管理

发展

  • typescript -传统服务器的类型安全
  • @types/node -Node.js类型定义

🔒 配置

AI提供商

为真实AI设置环境变量:

export OPENAI_API_KEY="your-key-here"
export ANTHROPIC_API_KEY="your-key-here"

或者使用内置的模拟人工智能进行测试(不需要API密钥)。

🧪 测试

综合测试

npm run test:agentic  # Test AI capabilities
npm run test         # Test traditional tools
npm run client       # Interactive testing

示例测试会话

  1. 启动服务器: npm run agentic
  2. 打开客户端: npm run client:interactive
  3. 尝试: ai help me understand this project
  4. 尝试: ai check weather in Tokyo and suggest activities

🌟 是什么让这个机构?

与传统的基于工具的MCP服务器不同,这个代理AI版本:

  • 理解意图:处理自然语言以理解你真正想要的东西
  • 自主计划:在没有明确指令的情况下创建多步骤执行策略
  • 关于上下文的原因:根据您的情况做出明智的决定
  • 学习和适应:改进基于对话历史记录的响应
  • 综合情报:将多个数据源组合成连贯的见解
  • 主动协助:建议您可能不考虑的改进和替代方案

📈 传统工具(向后兼容)

传统的MCP服务器仍可在 src/index.ts:

npm run build  # Build TypeScript
npm start      # Run traditional server

传统工具

  • get_weather -城市基本天气
  • read_file -读取文件内容
  • write_file -写入文件
  • list_files -列出目录内容

传统客户端示例

npm run client           # Simple test client
npm run client:advanced  # Advanced demo client
npm run client:typed     # TypeScript client

📈 路线图

  • 真正的AI集成:连接OpenAI/Anthropic API以供生产使用
  • 高级内存:持久存储和长期学习
  • 插件系统:可扩展的人工智能工具生态系统
  • 视觉界面:用于人工智能交互的基于网络的聊天界面
  • 多模态人工智能:支持图像、文档和富媒体

将您的MCP体验从简单的工具执行转变为智能AI辅助! 🚀