mcp-server-ex

ReadEin/mcp-server-ex

3.1

If you are the rightful owner of mcp-server-ex and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

This project is an example of a Model Context Protocol (MCP) server designed to create child processes through mcp-client in mcp-ai-core.

Tools
2
Resources
0
Prompts
0

Node Version

ํ˜„์žฌ ์ด ํ”„๋กœ์ ํŠธ๋Š” Node.js ๋ฒ„์ „ 20.11.x์—์„œ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

ํ”„๋กœ์ ํŠธ ์„ค๋ช…

์ด ํ”„๋กœ์ ํŠธ๋Š” mcp-ai-core์—์„œ mcp-client๋ฅผ ํ†ตํ•ด ์ž์‹ ํ”„๋กœ์„ธ์Šค๋ฅผ ์ƒ์„ฑํ•˜๋„๋ก ์„ค๊ณ„๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

MCP Server Example

Model Context Protocol (MCP) ์„œ๋ฒ„ ์˜ˆ์ œ ํ”„๋กœ์ ํŠธ์ž…๋‹ˆ๋‹ค.

ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ

mcp-server-ex/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ index.ts        # ๋ฉ”์ธ ์„œ๋ฒ„ ์„ค์ • ๋ฐ ์ดˆ๊ธฐํ™”
โ”‚   โ””โ”€โ”€ tool/
โ”‚       โ””โ”€โ”€ nws.ts      # National Weather Service ๋„๊ตฌ ๊ตฌํ˜„
โ”œโ”€โ”€ package.json
โ””โ”€โ”€ tsconfig.json

์ฃผ์š” ์ปดํฌ๋„ŒํŠธ

์„œ๋ฒ„ ์„ค์ • (src/index.ts)

  • MCP ์„œ๋ฒ„ ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ๋ฐ ์„ค์ •
  • ๊ธฐ๋ณธ ํ”„๋กฌํ”„ํŠธ ๋“ฑ๋ก
  • ๋„๊ตฌ ๋“ฑ๋ก ๋ฐ ์ดˆ๊ธฐํ™”
  • StdioServerTransport๋ฅผ ํ†ตํ•œ ํ†ต์‹  ์„ค์ •

NWS ๋„๊ตฌ (src/tool/nws.ts)

  • get-alerts: ํŠน์ • ์ฃผ(state)์˜ ๊ธฐ์ƒ ๊ฒฝ๋ณด ์กฐํšŒ
  • list_tools: ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋„๊ตฌ ๋ชฉ๋ก ๋ฐ˜ํ™˜
  • ๋ชจ์˜ API ์‘๋‹ต ๊ตฌํ˜„ (์‹ค์ œ API ํ˜ธ์ถœ ๋Œ€์‹  ํ…Œ์ŠคํŠธ์šฉ)

MCP ํ”„๋กœํ† ์ฝœ ๊ตฌํ˜„

์ง€์›ํ•˜๋Š” ๊ธฐ๋Šฅ

  • Resources: list, read
  • Tools: list, call
  • Prompts: list, get

๋„๊ตฌ ๋ชฉ๋ก

  1. get-alerts
    • ์„ค๋ช…: ํŠน์ • ์ฃผ์˜ ๊ธฐ์ƒ ๊ฒฝ๋ณด ์กฐํšŒ
    • ๋งค๊ฐœ๋ณ€์ˆ˜: state (2๊ธ€์ž ์ฃผ ์ฝ”๋“œ, ์˜ˆ: CA, NY)

์‹คํ–‰ ๋ฐฉ๋ฒ•

# ์˜์กด์„ฑ ์„ค์น˜
npm install

# ๋นŒ๋“œ
npm run build

# ์‹คํ–‰
npm start

๊ฐœ๋ฐœ ์ฐธ๊ณ ์‚ฌํ•ญ

  1. ์ƒˆ๋กœ์šด ๋„๊ตฌ ์ถ”๊ฐ€

    • src/tool/ ๋””๋ ‰ํ† ๋ฆฌ์— ์ƒˆ ๋„๊ตฌ ๊ตฌํ˜„
    • registerXxxTool ํ•จ์ˆ˜ ์ž‘์„ฑ
    • list_tools ์‘๋‹ต์— ์ƒˆ ๋„๊ตฌ ์ •๋ณด ์ถ”๊ฐ€
  2. ํ”„๋กฌํ”„ํŠธ ์ถ”๊ฐ€

    • server.prompt() ๋ฉ”์„œ๋“œ ์‚ฌ์šฉ
    • messages ๋ฐฐ์—ด์— ์‘๋‹ต ํฌํ•จ
  3. ๋„๊ตฌ ์‘๋‹ต ํ˜•์‹

    {
      content: [{
        type: "text",
        text: string
      }]
    }