mcpField
C
Candidate MCP Server Library

Candidate MCP Server Library

本地服务
github.com/jhgaylor开发工具8120 周前更新

关于 Candidate MCP Server Library

Candidate MCP Server Library 是一个 TypeScript 库,用于为 LLM 提供候选人信息的访问。它面向集成到其他应用中使用,而非作为独立服务运行,并支持 STDIO 与 HTTP 等传输方式。

主要功能

  1. 01以库的形式集成到其他应用
  2. 02提供简历、社交主页和个人网站资源
  3. 03提供对应的工具及可选的邮件联系功能
  4. 04支持 STDIO、HTTP 和 Streamable HTTP 传输

适用场景

  1. 01为招聘类 LLM 应用提供候选人背景信息
  2. 02在 Express 应用中挂载候选人信息 MCP 端点

MCP 相关

该库向 MCP 客户端暴露候选人简历、LinkedIn、GitHub 和个人网站等资源,并提供对应的工具,其中 contact_candidate 需要配置 Mailgun 才能发送邮件。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

候选人 MCP 服务库

一个 Model Context Protocol(MCP)服务,为大模型提供候选人的相关信息。

概览

重要提示:此服务旨在作为库集成到其他应用中,而非作为独立服务使用。提供的启动方法仅用于演示和测试。

资源

此 MCP 服务提供以下资源:

  • candidate-info://resume-text:简历文本内容
  • candidate-info://resume-url:简历 URL
  • candidate-info://linkedin-url:LinkedIn 个人资料 URL
  • candidate-info://github-url:GitHub 个人资料 URL
  • candidate-info://website-url:个人网站 URL
  • candidate-info://website-text:个人网站内容
工具

此 MCP 服务还提供返回相同候选人信息的工具:

  • get_resume_text:返回候选人的简历文本内容
  • get_resume_url:返回候选人简历的 URL
  • get_linkedin_url:返回候选人 LinkedIn 个人资料的 URL
  • get_github_url:返回候选人 GitHub 个人资料的 URL
  • get_website_url:返回候选人个人网站的 URL
  • get_website_text:返回候选人个人网站的内容
  • contact_candidate:向候选人发送电子邮件(需要配置 Mailgun)

用法

npm install @jhgaylor/candidate-mcp-server

库用法

此软件包旨在导入并用于你自己的应用中。

Stdio

通过 stdio 启动进程非常简单。关键在于提供候选人配置。

候选人配置的来源完全由你决定。也许你会将其硬编码,也许会在启动进程时传入 JSONResume URL。由你决定!

import { createServer } from '@jhgaylor/candidate-mcp-server';
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";

// Configure your server
const serverConfig = { 
  name: "MyCandidateServer", 
  version: "1.0.0",
  mailgunApiKey: process.env.MAILGUN_API_KEY,
  mailgunDomain: process.env.MAILGUN_DOMAIN
};
const candidateConfig = { 
  name: "John Doe",
  email: "[email protected]", // Required for the contact_candidate tool
  resumeUrl: "https://example.com/resume.pdf",
  // other candidate properties
};

// Create server instance
const server = createServer(serverConfig, candidateConfig);

// Connect with your preferred transport
await server.connect(new StdioServerTransport());
// or integrate with your existing HTTP server
StreamableHttp

使用 typescript sdk 提供的示例代码,我们可以将此 mcp 服务绑定到 express 服务。

import express from 'express';
import { Request, Response } from 'express';
import { createServer } from '@jhgaylor/candidate-mcp-server';
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamablehttp.js";

// Configure your server
const serverConfig = { 
  name: "MyCandidateServer", 
  version: "1.0.0",
  mailgunApiKey: process.env.MAILGUN_API_KEY,
  mailgunDomain: process.env.MAILGUN_DOMAIN,
  contactEmail: "[email protected]",
};
const candidateConfig = { 
  name: "John Doe",
  resumeUrl: "https://example.com/resume.pdf",
  // other candidate properties
};

// Factory function to create a new server instance for each request
const getServer = () => createServer(serverConfig, candidateConfig);

const app = express();
app.use(express.json());

app.post('/mcp', async (req: Request, res: Response) => {
  // In stateless mode, create a new instance of transport and server for each request
  // to ensure complete isolation. A single instance would cause request ID collisions
  // when multiple clients connect concurrently.
  
  try {
    const server = getServer(); 
    const transport = new StreamableHTTPServerTransport({
      sessionIdGenerator: undefined,
    });
    res.on('close', () => {
      console.log('Request closed');
      transport.close();
      server.close();
    });
    await server.connect(transport);
    await transport.handleRequest(req, res, req.body);
  } catch (error) {
    console.error('Error handling MCP request:', error);
    if (!res.headersSent) {
      res.status(500).json({
        jsonrpc: '2.0',
        error: {
          code: -32603,
          message: 'Internal server error',
        },
        id: null,
      });
    }
  }
});

app.get('/mcp', async (req: Request, res: Response) => {
  console.log('Received GET MCP request');
  res.writeHead(405).end(JSON.stringify({
    jsonrpc: "2.0",
    error: {
      code: -32000,
      message: "Method not allowed."
    },
    id: null
  }));
});

app.delete('/mcp', async (req: Request, res: Response) => {
  console.log('Received DELETE MCP request');
  res.writeHead(405).end(JSON.stringify({
    jsonrpc: "2.0",
    error: {
      code: -32000,
      message: "Method not allowed."
    },
    id: null
  }));
});

// Start the server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`MCP Stateless Streamable HTTP Server listening on port ${PORT}`);
});
Express

你也可以使用 express-mcp-handler 来完成 express 与 mcp 传输之间的绑定,无需自行编写。

npm install express-mcp-handler

import express from 'express';
import { statelessHandler } from 'express-mcp-handler';
import { createServer } from './server';

// You can configure the server factory to include Mailgun settings
const createServerWithConfig = () => {
  const serverConfig = { 
    name: "MyCandidateServer", 
    version: "1.0.0",
    mailgunApiKey: process.env.MAILGUN_API_KEY,
    mailgunDomain: process.env.MAILGUN_DOMAIN,
    contactEmail: "[email protected]",
  };
  const candidateConfig = { 
    name: "John Doe",
    resumeUrl: "https://example.com/resume.pdf",
    // other candidate properties
  };
  
  return createServer(serverConfig, candidateConfig);
};

// Configure the stateless handler
const handler = statelessHandler(createServerWithConfig);

// Create Express app
const app = express();
app.use(express.json());

// Mount the handler (stateless only needs POST)
app.post('/mcp', handler);

// Start the server
const PORT = process.env.PORT || 3002;
app.listen(PORT, () => {
  console.log(`Stateless MCP server running on port ${PORT}`);
});

开发

# Install dependencies
npm install

# Build the project
npm run build

# Run in development mode with auto-restart
npm run dev
通过 stdio 演示/调试启动
# Start with STDIO (demo only)
npm start

使用 STDIO 运行时,可以通过发送单行 JSON 对象形式的 MCP 消息与服务交互:

# Example of sending an initialize message via STDIO
echo '{"jsonrpc": "2.0","id": 1,"method": "initialize","params": {"protocolVersion": "2024-11-05","capabilities": {"roots": {"listChanged": true},"sampling": {}},"clientInfo": {"name": "ExampleClient","version": "1.0.0"}}}' | node dist/index.js --stdio

# List resources
echo '{"jsonrpc": "2.0","id": 2,"method": "resources/list","params": {}}' | node dist/index.js --stdio

# Access a resource
echo '{"jsonrpc": "2.0","id": 3,"method": "resources/read","params": {"uri": "candidate-info://resume-text"}}' | node dist/index.js --stdio

# List Tools
echo '{"jsonrpc": "2.0","id": 2,"method": "tools/list","params": {}}' | node dist/index.js --stdio

# Call a tool
echo '{"jsonrpc": "2.0","id": 4,"method": "tools/call","params": {"name": "get_resume_text", "args": {}}}' | node dist/index.js --stdio

# Send an email to the candidate
echo '{"jsonrpc": "2.0","id": 5,"method": "tools/call","params": {"name": "contact_candidate", "args": {"subject": "Hello from AI!", "message": "This is a test email sent via the MCP server.", "reply_address": "[email protected]"}}}' | node dist/index.js --stdio

每条消息都必须位于单独一行,JSON 对象内部不能换行。

功能

  • 以库为先的设计,便于集成到其他应用中
  • 模块化资源系统,可扩展自定义候选人信息
  • 使用 TypeScript 提供类型安全和更好的开发体验
  • 实现完整的 Model Context Protocol 规范
  • 支持多种传输类型(STDIO、HTTP、Streamable HTTP)
  • 依赖项精简

服务结构

src/
  ├── index.ts                # Main package entry point
  ├── server.ts               # MCP server factory with configuration
  ├── config.ts               # Configuration type definitions
  └── resources/              # Modular resource definitions
      └── index.ts            # Resource factory and implementation

MCP 协议

此库实现了 Model Context Protocol(MCP),这是一种标准化方式,让大模型能够与外部数据和功能交互。集成到应用后,它会公开一个无状态 API,用于响应 JSON-RPC 请求。

API 用法

集成到应用后,客户端可以通过发送 JSON-RPC 请求与 MCP 服务交互。以下是集成此库后,应用需要处理的请求示例:

初始化
curl -X POST http://your-application-url/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "Accept: text/event-stream" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "initialize",
    "params": {
      "protocolVersion": "2024-11-05",
      "capabilities": {
        "roots": {
          "listChanged": true
        },
        "sampling": {}
      },
      "clientInfo": {
        "name": "ExampleClient",
        "version": "1.0.0"
      }
    }
  }'
访问候选人资源
curl -X POST http://your-application-url/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "Accept: text/event-stream" \
  -d '{
    "jsonrpc": "2.0",
    "method": "resources/read",
    "params": {
      "uri": "candidate-info://resume-text"
    },
    "id": 2
  }'

扩展库

此库旨在通过自定义资源、工具和提示词进行扩展。以下是添加自定义资源的方法:

import { McpServer, Resource } from '@jhgaylor/candidate-mcp-server';

// Create your custom resource class
class CustomCandidateResource extends Resource {
  constructor(candidateConfig) {
    super(
      `${candidateConfig.name} Custom Data`, 
      "candidate-info://custom-data", 
      async () => {
        return {
          contents: [
            { 
              uri: "candidate-info://custom-data", 
              mimeType: "text/plain", 
              text: "Your custom candidate data here"
            }
          ]
        };
      }
    );
  }
}

// Create server with standard configuration
const server = createServer(serverConfig, candidateConfig);

// Add your custom resource
const customResource = new CustomCandidateResource(candidateConfig);
customResource.bind(server);

// Connect with preferred transport
// ...
添加自定义工具

你也可以使用自定义工具扩展此库:

import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { z } from 'zod';
import { createServer } from '@jhgaylor/candidate-mcp-server';

// Create server with standard configuration
const server = createServer(serverConfig, candidateConfig);

// Add a custom tool
server.tool(
  'get_candidate_skills',
  'Returns a list of the candidate skills',
  {},
  async (_args, _extra) => {
    return {
      content: [
        { 
          type: "text", 
          text: "JavaScript, TypeScript, React, Node.js, MCP Protocol" 
        }
      ]
    };
  }
);

// Connect with preferred transport
// ...

要求

  • Node.js 20+
  • npm 或 yarn

许可证

MIT

发布到 npm

如果尚未登录 npm,请先登录:

npm login

将软件包发布到 npm(将运行 prepublishOnly 构建):

npm publish

递增版本号、打标签并推送新版本:

npm version patch    # or minor, major
git push origin main --tags

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。