Skip to main content
Glama
gayatrianne

langgraph-mcp-aws-dynamodb-agent

by gayatrianne

LangGraph MCP AWS DynamoDB CRM Agent

Galaxy Telecom — 通过 Model Context Protocol 实现标准化 AI 工具集成

一个生产级 AI 代理,演示 MCP(Model Context Protocol)与 AWS DynamoDB 的集成——通过标准化工具协议而非定制化集成,将 LangGraph 代理连接到实时 CRM 数据。

📄 作品集文档 (PDF) — 包含架构、AWS DynamoDB 设置和示例交互的完整文档


概述

需要 CRM 数据的传统 AI 代理需要硬编码集成——为每个外部系统编写定制代码,与代理逻辑紧密耦合。本项目演示了一种更好的方法:代理在运行时连接到 Python MCP 服务器,动态发现可用工具,并调用它们从 AWS DynamoDB 检索实时客户账户和工单数据——代理中零硬编码集成逻辑。


Related MCP server: Agorus MCP Server

什么是 MCP?

MCP(Model Context Protocol)是 Anthropic 推出的开放标准,定义了 AI 代理如何连接到外部工具和数据源。MCP 之于 AI 代理,正如 REST API 之于 Web 服务——一种通用契约,无需为每次集成定制适配器即可实现互操作性。

关键能力是运行时工具发现。代理在启动时不知道存在哪些工具。它连接到 MCP 服务器并询问"你能做什么?"服务器返回工具名称、描述和输入模式。然后代理根据客户查询决定调用哪些工具。


架构

Customer CLI Input
        │
        ▼
┌─────────────────────┐
│   LangGraph Agent   │  ← ReAct pattern, Claude Haiku (Anthropic API)
│   (crm_agent.py)    │
└──────────┬──────────┘
           │ MCP protocol — stdio transport
           │ Runtime tool discovery via get_tools()
           ▼
┌─────────────────────┐
│    MCP Server       │  ← FastMCP, Python
│    (server.py)      │
│                     │
│  get_customer_      │  ← queries CustomerAccounts table
│  account()          │
│                     │
│  get_open_          │  ← queries SupportTickets table
│  tickets()          │
└──────────┬──────────┘
           │ boto3
           ▼
┌─────────────────────┐
│   AWS DynamoDB      │  ← eu-west-1
│                     │
│ GalaxyTelecom_      │
│ CustomerAccounts    │
│                     │
│ GalaxyTelecom_      │
│ SupportTickets      │
└─────────────────────┘

MCP 工具定义

工具使用 @server.tool() 装饰器在 MCP 服务器上注册。代理对这些函数一无所知——它通过协议在运行时动态接收它们的定义。

@server.tool()
def get_customer_account(customer_id: str) -> str:
    """
    Retrieve a Galaxy Telecom customer account from DynamoDB.
    Returns account details including plan, status, and balance due.
    """
    ...

@server.tool()
def get_open_tickets(customer_id: str) -> str:
    """
    Retrieve all open support tickets for a Galaxy Telecom customer.
    Returns a list of tickets with issue type, description, status and priority.
    """
    ...

将 DynamoDB 替换为 Salesforce 或 Dynamics 只需要实现一个新的 MCP 服务器。代理代码完全保持不变——这证明了该协议的可移植性优势。


AWS DynamoDB 表

GalaxyTelecom_CustomerAccounts

  • 分区键:customer_id

  • 存储:姓名、电子邮件、套餐、月费、账户状态、欠款余额、加入时间

GalaxyTelecom_SupportTickets

  • 分区键:customer_id,排序键:ticket_id

  • 存储:问题类型、描述、状态、提出日期、分配团队、优先级

  • 复合键支持通过一次查询获取客户的所有工单


示例交互

逾期账户且有未结工单(C001)

Customer ID : C001
Message     : Hi, I wanted to check on my account and see if there are any issues.

[MCP] Tools discovered: ['get_customer_account', 'get_open_tickets']

Response: Hi John, I can see your account is overdue with a balance of £47.50.
You have 2 open tickets — a billing query (T001, medium priority) and
broadband dropouts (T002, high priority, in progress with Technical Support)...

活跃账户,存在技术工单(C002)

Customer ID : C002
Message     : I have been having some signal issues at home, can you help?

Response: Hello Sarah! I can see you're on our EliteMax plan with no balance due.
You've already raised ticket T003 regarding weak 5G signal — an engineer
visit has been requested, marked medium priority...

无效客户 ID——优雅的错误处理

Customer ID : 99
Message     : I have been having some signal issues at home, can you help?

Response: I'm unable to locate a Galaxy Telecom account associated with
Customer ID 99. The ID may have been entered incorrectly...

技术栈

组件

技术

代理编排

LangGraph (ReAct pattern)

LLM 框架

LangChain

LLM 提供商

Anthropic Claude Haiku API

MCP 协议

Model Context Protocol (FastMCP)

MCP 适配器

langchain-mcp-adapters

CRM 数据存储

AWS DynamoDB (eu-west-1)

AWS SDK

boto3

语言

Python 3.11+


项目结构

langgraph-mcp-aws-dynamodb-agent/
├── agent/
│   ├── __init__.py
│   └── crm_agent.py        # LangGraph ReAct agent — connects to MCP server
├── dynamo/
│   ├── __init__.py
│   └── seed_data.py        # Creates DynamoDB tables and seeds mock CRM data
├── mcp_server/
│   ├── __init__.py
│   └── server.py           # MCP server — exposes CRM tools backed by DynamoDB
├── main.py                 # Interactive CLI entry point
├── requirements.txt
├── .env.example            # Environment variable template
└── .gitignore

设置与安装

前提条件

  • Python 3.11+

  • Anthropic API 密钥

  • 已配置 CLI 的 AWS 账户(aws configure

  • 具有 DynamoDB 读写权限的 IAM 用户

安装

# Clone the repository
git clone https://github.com/gayatrianne/langgraph-mcp-aws-dynamodb-agent.git
cd langgraph-mcp-aws-dynamodb-agent

# Create and activate virtual environment
python -m venv venv
venv\Scripts\activate        # Windows
source venv/bin/activate     # macOS/Linux

# Install dependencies
pip install -r requirements.txt

# Configure environment variables
cp .env.example .env
# Edit .env and add your Anthropic API key

环境变量

# Anthropic
ANTHROPIC_API_KEY=your_key_here

# AWS — credentials come from AWS CLI profile (aws configure)
AWS_REGION=eu-west-1

# DynamoDB table names
CUSTOMER_TABLE=GalaxyTelecom_CustomerAccounts
TICKETS_TABLE=GalaxyTelecom_SupportTickets

# LLM Configuration
CLAUDE_MODEL=claude-haiku-4-5-20251001
CLAUDE_TEMPERATURE=0.3

初始化 DynamoDB 表

在启动代理前运行一次:

python dynamo/seed_data.py

这将在 eu-west-1 中创建两个 DynamoDB 表,并使用模拟的 Galaxy Telecom 客户记录和支持工单填充数据。

运行

python main.py

输入客户 ID(C001、C002、C003、C004)和支持消息。代理将发现 MCP 工具、查询 DynamoDB,并返回基于实时 CRM 数据的个性化响应。


关键设计决策

通过 MCP 实现运行时工具发现 代理在运行时调用 await client.get_tools()——在询问 MCP 服务器之前,它不知道存在哪些工具。这是协议的核心优势:代理与实现解耦。

优雅的错误处理 无效客户 ID 从 MCP 服务器返回结构化错误 JSON。代理自然地解释这些错误并做出有帮助的响应,而不会向客户暴露技术细节。

MCP 可移植性 将 DynamoDB 替换为 Salesforce、Dynamics 或任何其他 CRM 只需要实现一个新的 MCP 服务器。crm_agent.py 中的 LangGraph 代理代码完全保持不变——代理通过协议层与数据源解耦。

AWS DynamoDB 数据模型 CustomerAccounts 使用单一分区键(customer_id)。SupportTickets 使用复合键(customer_id + ticket_id)——通过一次查询即可返回客户的所有工单,反映了真实 CRM 数据访问模式。


展示的技能

  • Model Context Protocol (MCP) — 标准化 AI 工具集成

  • 运行时工具发现 — 代理动态发现工具,无需硬编码

  • LangGraph 代理编排 — 带外部工具调用的 ReAct 模式

  • AWS DynamoDB — 带分区键和排序键的 NoSQL CRM 数据存储

  • boto3 — Python 的 AWS SDK

  • FastMCP — Python MCP 服务器框架

  • 优雅的错误处理 — 结构化 MCP 错误响应

  • 外部化配置 — 通过环境变量配置模型和区域


作者

Gayatri Anne AI 与云架构师 | 18 年以上企业 IT 经验

我构建 AI 驱动的自动化系统,消除业务流程中的手工工作,将代理工作流、大语言模型和云集成相结合,交付生产级解决方案。

认证:Azure Solutions Architect Expert | Azure AI Engineer Associate | Python PCAP | TOGAF Foundation

GitHub: gayatrianne

F
license - not found
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

View all related MCP servers

Related MCP Connectors

  • MCP server exposing the Backtest360 engine API as tools for AI agents.

  • Hosted Amazon Seller Central and Amazon Ads MCP server for Claude, ChatGPT, Cursor, and agents.

  • Hosted Amazon Seller and Vendor MCP server for Claude, ChatGPT, Cursor, Codex, Gemini, Copilot.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/gayatrianne/langgraph-mcp-aws-dynamodb-agent'

If you have feedback or need assistance with the MCP directory API, please join our Discord server