PY

langgraph-dynamic-mcp-agents

by teddynote-lab/langgraph-dynamic-mcp-agents

0 views

LangGraph ReAct Agents with an ability to use MCP Tools dynamically

pythonChat & Messaging

LangGraph Dynamic MCP Agents

Python LangChain LangGraph Open in - LangGraph Studio

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

์ฑ„ํŒ… ์ธํ„ฐํŽ˜์ด์Šค

Project Overview

LangGraph Dynamic MCP Agents ์€ Model Context Protocol(MCP)์„ ํ†ตํ•ด ๋‹ค์–‘ํ•œ ์™ธ๋ถ€ ๋„๊ตฌ์™€ ๋ฐ์ดํ„ฐ ์†Œ์Šค์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ReAct ์—์ด์ „ํŠธ๋ฅผ ๊ตฌํ˜„ํ•œ ํ”„๋กœ์ ํŠธ์ž…๋‹ˆ๋‹ค. ์ด ํ”„๋กœ์ ํŠธ๋Š” LangGraph ์˜ ReAct ์—์ด์ „ํŠธ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•˜๋ฉฐ, MCP ๋„๊ตฌ๋ฅผ ์‰ฝ๊ฒŒ ์ถ”๊ฐ€ํ•˜๊ณ  ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

Project Demo

์ฃผ์š” ๊ธฐ๋Šฅ

๋™์  ๋ฐฉ์‹์œผ๋กœ ๋„๊ตฌ ์„ค์ • ๋Œ€์‹œ๋ณด๋“œ

http://localhost:2025 ์— ์ ‘์†ํ•˜์—ฌ ๋„๊ตฌ ์„ค์ • ๋Œ€์‹œ๋ณด๋“œ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Tool Settings

๋„๊ตฌ ์ถ”๊ฐ€ ํƒญ์—์„œ Smithery ์—์„œ ์‚ฌ์šฉํ•  MCP ๋„๊ตฌ์˜ JSON ๊ตฌ์„ฑ์„ ๋ณต์‚ฌ ๋ถ™์—ฌ๋„ฃ๊ธฐ ํ•˜์—ฌ ๋„๊ตฌ๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Tool Settings


์‹ค์‹œ๊ฐ„ ๋ฐ˜์˜

๋„๊ตฌ ์„ค์ • ๋Œ€์‹œ๋ณด๋“œ์—์„œ ๋„๊ตฌ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ์ˆ˜์ •ํ•˜๋ฉด ์‹ค์‹œ๊ฐ„์œผ๋กœ ๋ฐ˜์˜๋ฉ๋‹ˆ๋‹ค.

List Tools

์‹œ์Šคํ…œ ํ”„๋กฌํ”„ํŠธ ์„ค์ •

prompts/system_prompt.yaml ํŒŒ์ผ์„ ์ˆ˜์ •ํ•˜์—ฌ ์‹œ์Šคํ…œ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ๋˜ํ•œ ๋™์ ์œผ๋กœ ๋ฐ”๋กœ ๋ฐ˜์˜๋˜๋Š” ํ˜•ํƒœ์ž…๋‹ˆ๋‹ค.

System Prompt

๋งŒ์•ฝ, ์—์ด์ „ํŠธ์— ์„ค์ •๋˜๋Š” ์‹œ์Šคํ…œํ”„๋กฌํ”„ํŠธ๋ฅผ ์ˆ˜์ •ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด prompts/system_prompt.yaml ํŒŒ์ผ์˜ ๋‚ด์šฉ์„ ์ˆ˜์ •ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.


์ฃผ์š” ๊ธฐ๋Šฅ

  • LangGraph ReAct ์—์ด์ „ํŠธ: LangGraph๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•˜๋Š” ReAct ์—์ด์ „ํŠธ
  • ์‹ค์‹œ๊ฐ„ ๋™์  ๋„๊ตฌ ๊ด€๋ฆฌ: MCP ๋„๊ตฌ๋ฅผ ์‰ฝ๊ฒŒ ์ถ”๊ฐ€, ์ œ๊ฑฐ, ๊ตฌ์„ฑ ๊ฐ€๋Šฅ (Smithery JSON ํ˜•์‹ ์ง€์›)
  • ์‹ค์‹œ๊ฐ„ ๋™์  ์‹œ์Šคํ…œ ํ”„๋กฌํ”„ํŠธ ์„ค์ •: ์‹œ์Šคํ…œ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์‰ฝ๊ฒŒ ์ˆ˜์ • ๊ฐ€๋Šฅ (๋™์  ๋ฐ˜์˜)
  • ๋Œ€ํ™” ๊ธฐ๋ก: ์—์ด์ „ํŠธ์™€์˜ ๋Œ€ํ™” ๋‚ด์šฉ ์ถ”์  ๋ฐ ๊ด€๋ฆฌ
  • TeddyFlow ์—ฐ๋™: ์ฑ„ํŒ… ์ธํ„ฐํŽ˜์ด์Šค ์—ฐ๋™
  • Docker ์ด๋ฏธ์ง€ ๋นŒ๋“œ: Docker ์ด๋ฏธ์ง€ ๋นŒ๋“œ ๊ฐ€๋Šฅ
  • localhost ์ง€์›: localhost ๋กœ ์‹คํ–‰ ๊ฐ€๋Šฅ(์ฑ„ํŒ… ์ธํ„ฐํŽ˜์ด์Šค ์—ฐ๋™ ๊ฐ€๋Šฅ)

์„ค์น˜ ๋ฐฉ๋ฒ•

  1. ์ €์žฅ์†Œ ๋ณต์ œํ•˜๊ธฐ
git clone https://github.com/teddynote-lab/langgraph-dynamic-mcp-agents
cd langgraph-dynamic-mcp-agents
  1. .env ํŒŒ์ผ ์„ค์ •ํ•˜๊ธฐ

.env.example ํŒŒ์ผ์„ .env๋กœ ๋ณต์‚ฌํ•˜๊ณ  ํ•„์š”ํ•œ API ํ‚ค๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

cp .env.example .env

.env ํŒŒ์ผ์—์„œ LLM_PROVIDER ๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

์„ ํƒ ๊ฐ€๋Šฅ(ํƒ 1): ANTHROPIC, OPENAI, AZURE_OPENAI

LLM_PROVIDER=AZURE_OPENAI

์•„๋ž˜๋Š” ํ•„์š”ํ•œ API ํ‚ค ๋ชฉ๋ก์ž…๋‹ˆ๋‹ค. (์„ ํƒํ•œ LLM_PROVIDER ์— ๋”ฐ๋ผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค)

Anthropic, OpenAI, Azure OpenAI ์—์„œ ์‚ฌ์šฉํ•  API ํ‚ค๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.(๋ฐ˜๋“œ์‹œ ํ•˜๋‚˜์˜ ๋ชจ๋ธ์€ ์„ค์ •๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.)

  • ANTHROPIC_API_KEY: Anthropic API ํ‚ค
  • OPENAI_API_KEY: OpenAI API ํ‚ค
  • AZURE_OPENAI_API_KEY: Azure OpenAI API ํ‚ค
  • AZURE_OPENAI_ENDPOINT: Azure OpenAI ์—”๋“œํฌ์ธํŠธ
  1. MCP ๋„๊ตฌ ์„ค์ •

mcp-config ํด๋”์— ์žˆ๋Š” mcp_config.json ํŒŒ์ผ์„ ๊ธฐ์ค€์œผ๋กœ ๋ชจ๋ธ์ด ์‚ฌ์šฉํ•  MCP ๋„๊ตฌ๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ, ๋ฏธ๋ฆฌ ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” MCP ๋„๊ตฌ๋ฅผ JSON ํ˜•์‹์œผ๋กœ ์„ค์ •ํ•ด ๋‘˜ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๊ณผ์ •์€ ๋„๊ตฌ ์„ค์ • ๋Œ€์‹œ๋ณด๋“œ์—์„œ๋„ ์„ค์ •์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์•„๋ž˜๋Š” ์ƒ˜ํ”Œ๋กœ ์ž‘์„ฑ๋œ ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค.

{
  "mcpServers": {
    "perplexity-search": {
      "command": "npx",
      "args": [
        "-y",
        "@smithery/cli@latest",
        "run",
        "@arjunkmrm/perplexity-search",
        "--key",
        "SMITHERY_API_KEY ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”"
      ],
      "transport": "stdio"
    },
    "get_current_time": {
      "command": "python",
      "args": [
        "/app/resources/mcp_server_time.py"
      ],
      "transport": "stdio"
    }
  }
}
  1. .py ํŒŒ์ผ์„ MCP stdio ์„œ๋ฒ„๋กœ ์ถ”๊ฐ€
  • (์ฐธ๊ณ ) resources ํด๋”์— ์žˆ๋Š” mcp_server_time.py ํŒŒ์ผ์„ ์ฐธ๊ณ ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.
  1. ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” ์ปค์Šคํ…€ ์ž‘์„ฑ๋œ .py ํŒŒ์ผ์„ resources ํด๋”์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  stdio ์„œ๋ฒ„๋กœ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋„๋ก ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

  2. mcp-config/mcp_config.json ์— ์ถ”๊ฐ€ํ•  ๋•Œ ํŒŒ์ผ ๊ฒฝ๋กœ๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

    ๊ทœ์น™

    ./resources/ํŒŒ์ผ๋ช….py > /app/resources/ํŒŒ์ผ๋ช….py

    ์˜ˆ๋ฅผ ๋“ค์–ด, ./resources/mcp_server_time.py ํŒŒ์ผ์„ ์ถ”๊ฐ€ํ•˜๊ณ ์ž ํ•œ๋‹ค๋ฉด /app/resources/mcp_server_time.py ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

    "get_current_time": {
        "command": "python",
        "args": [
        "/app/resources/mcp_server_time.py"
        ],
        "transport": "stdio"
    }
    
  3. Smithery ์— ๋“ฑ๋ก๋œ ๋„๊ตฌ ์ถ”๊ฐ€

Smithery ์—์„œ ์‚ฌ์šฉํ•  MCP ๋„๊ตฌ์˜ JSON ๊ตฌ์„ฑ์„ ๊ฐ€์ ธ์™€ ๋„๊ตฌ ๋Œ€์‹œ๋ณด๋“œ์—์„œ ์‰ฝ๊ฒŒ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  1. Smithery ์›น์‚ฌ์ดํŠธ๋ฅผ ๋ฐฉ๋ฌธํ•˜์—ฌ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์€ ๋„๊ตฌ๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.
  2. ๋„๊ตฌ ํŽ˜์ด์ง€์—์„œ ์˜ค๋ฅธ์ชฝ์˜ 'COPY' ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์—ฌ JSON ๊ตฌ์„ฑ์„ ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค.

Smithery Copy JSON

  1. mcp_config.json ํŒŒ์ผ์„ ์—ด๊ณ  ๋ณต์‚ฌํ•œ JSON์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

๋ณต์‚ฌํ•œ ๋‚ด์šฉ์„ ๋ถ™์—ฌ๋„ฃ๊ธฐ ํ•ฉ๋‹ˆ๋‹ค.

Add Smithery Tool

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰

๋ชจ๋“  ์„ค์ •์ด ์™„๋ฃŒ๋˜์—ˆ๋‹ค๋ฉด, ๋‹ค์Œ ๋ช…๋ น์–ด๋กœ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Windows(PowerShell)

docker compose build --no-cache; docker-compose up -d

Mac / Linux

docker compose build --no-cache && docker-compose up -d

์ ‘์† ์ฃผ์†Œ

  • TeddyFlow ์—ฐ๋™: https://teddyflow.com/
  • ์ฑ„ํŒ… ์ธํ„ฐํŽ˜์ด์Šค: http://localhost:2024
  • ๋„๊ตฌ ์„ค์ • ๋Œ€์‹œ๋ณด๋“œ: http://localhost:2025

teddyflow.com ์—ฐ๊ฒฐ ๋ฐฉ๋ฒ•

  1. teddyflow.com ์—์„œ ํšŒ์›๊ฐ€์ž…์„ ํ•ฉ๋‹ˆ๋‹ค.

ํšŒ์›๊ฐ€์ž…์‹œ "๋ฒ ํƒ€ ํ‚ค" ์— teddynote-youtube ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์Šน์ธ ์—†์ด ๋ฐ”๋กœ ๊ฐ€์ž…์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

teddyflow-code

  1. ๋กœ๊ทธ์ธ ํ›„ "์ƒˆ๋กœ์šด ์•ฑ ์—ฐ๊ฒฐ" ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

teddyflow-guide-01

  1. ์•ฑ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜๊ณ  "์—ฐ๊ฒฐ" ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.
  2. ํƒญ์—์„œ "LangGraph" ๋ฅผ ์„ ํƒํ•œ ๋’ค ๋‹ค์Œ์˜ ์ •๋ณด๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
  • Endpoint: http://localhost:2024
  • Graph: agent

teddyflow-guide-02

  1. ์—ฐ๊ฒฐ ์„ค์ •์ด ์™„๋ฃŒ๋˜๋ฉด "์ €์žฅ" ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

  2. "์•ฑ ์—ฐ๊ฒฐํ•˜๊ธฐ" ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

ํšŒ์‚ฌ๋ช… / ์ปค๋ฎค๋‹ˆํ‹ฐ ๋กœ๊ณ  ๋ฐ ๋ธŒ๋žœ๋”ฉ ์ ์šฉ

ํšŒ์‚ฌ๋ช… / ์ปค๋ฎค๋‹ˆํ‹ฐ๋ฅผ ์œ„ํ•œ ์ปค์Šคํ…€ ๊ธฐ๋Šฅ์„ ์ถœ์‹œํ•˜์˜€์Šต๋‹ˆ๋‹ค.

teddyflow-company

๋„์ž…์„ ํฌ๋งํ•˜์‹ ๋‹ค๋ฉด [email protected] ์œผ๋กœ ๋ฌธ์˜์ฃผ์‹œ๋ฉด ๋„์›€์„ ๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค.

๋ผ์ด์„ผ์Šค

Apache License 2.0 (LICENSE)

Install

{
  "mcpServers": {
    "langgraph-dynamic-mcp-agents": {
      "command": "npx",
      "args": [
        "-y",
        "@smithery/cli@latest",
        "run",
        "@arjunkmrm/perplexity-search",
        "--key",
        "SMITHERY_API_KEY ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”"
      ]
    }
  }
}
For more configuration details, refer to the content on the left

Related

Related projects feature coming soon

Will recommend related projects based on sub-categories