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
๋๊ตฌ ๋ชฉ๋ก
- get-alerts
- ์ค๋ช : ํน์ ์ฃผ์ ๊ธฐ์ ๊ฒฝ๋ณด ์กฐํ
- ๋งค๊ฐ๋ณ์: state (2๊ธ์ ์ฃผ ์ฝ๋, ์: CA, NY)
์คํ ๋ฐฉ๋ฒ
# ์์กด์ฑ ์ค์น
npm install
# ๋น๋
npm run build
# ์คํ
npm start
๊ฐ๋ฐ ์ฐธ๊ณ ์ฌํญ
-
์๋ก์ด ๋๊ตฌ ์ถ๊ฐ
src/tool/
๋๋ ํ ๋ฆฌ์ ์ ๋๊ตฌ ๊ตฌํregisterXxxTool
ํจ์ ์์ฑlist_tools
์๋ต์ ์ ๋๊ตฌ ์ ๋ณด ์ถ๊ฐ
-
ํ๋กฌํํธ ์ถ๊ฐ
server.prompt()
๋ฉ์๋ ์ฌ์ฉ- messages ๋ฐฐ์ด์ ์๋ต ํฌํจ
-
๋๊ตฌ ์๋ต ํ์
{ content: [{ type: "text", text: string }] }