显示HN:ASYNCMCP - 通过AWS SNS+SQS运行MCP通过异步运输
Show HN: asyncmcp – Run MCP over async transport via AWS SNS+SQS

原始链接: https://github.com/bh-rat/asyncmcp

ASYNCMCP扩展了MCP(机器理解协议)以支持异步通信,从而实现了基于队列的体系结构。这解决了应用程序需要时间来处理LLMS上下文的情况,避免了对MCP层中进行轮询包装的需求。使用SNS-SQS之类的传输,MCP服务器可以通过将其放置在队列上并稍后响应来异步处理请求。客户将请求写入主题,并听取响应的队列。 该库提供`sns_sqs_server'和`sns_sqs_client`类,需要AWS凭据和SNS/SQS配置。主要考虑因素包括SQS消息大小限制,异步响应处理,服务器端会话上下文管理以及潜在的标准SQ中缺乏保证的消息顺序。开发人员可以在项目存储库中找到详细的示例,以促进实施。

Bharatgel的“ AsynCMCP”项目,允许MCP(可能参考模型控制程序或类似的机器学习控制系统)使用AWS SNS和SQ不同步,从而获得了吸引。该解决方案解决了长期运行的LLM查询工作负载的挑战,这些工作量通常需要经纪和处理,而不是直接等待。一位用户,CriticalPudding发现它非常适合他们的工具,该工具需要几分钟才能完成,以取代其基于不理想的投票方法来检索结果。 Awsanswers还强烈支持此消息排队策略,用于针对特定于任务的LLM工作流程。巴拉特格(Bharatgel)很高兴以他们的方法看到共鸣。该线程还包括有关Y Combinator 2025秋季应用程序截止日期的提醒。
相关文章

原文

License Python Version


A regular MCP Server but working over queues :

queue-based-mcp-example.mov

Quoting from the official description :

MCP is an open protocol that standardizes how applications provide context to LLMs.

But a lot of this context is not always readily available and takes time for the applications to process - think batch processing APIs, webhooks or queues. In these cases with the current transport layers, the MCP server would have to expose a light-weight polling wrapper in the MCP layer to allow waiting and polling for the tasks to be done. Although SSE does provide async functionalities but it comes with caveats.

asyncmcp explores supporting more of the async transport layer implementations for MCP clients and servers, beyond the officially supported stdio and Streamable Http transports.

The whole idea of an MCP server with async transport layer is that it doesn't have to respond immediately to any requests. It can choose to direct them to internal queues for processing and the client doesn't have to stick around for the response.

Transport layer : sns-sqs

  • Server : Transport layer that listens to a queue for MCP requests and writes the responses to a topic
  • Client : Transport layer that writes requests to a topic and listens to a queue for responses
# Using uv (recommended)
uv add asyncmcp
# Using pip  
pip install asyncmcp

Note : we don't support FastMCP yet. The examples in this repo uses the basic way of creating MCP servers and client
Here's a basic example of implementing an MCP server which supports sns-sqs as the transport layer:

import boto3
from asyncmcp.sns_sqs.server import sns_sqs_server
from asyncmcp import SnsSqsTransportConfig

# Configure transport
config = SnsSqsTransportConfig(
    sqs_queue_url="https://sqs.region.amazonaws.com/account/service-queue",
    sns_topic_arn="arn:aws:sns:region:account:mcp-responses"
)  # more configurable params available.

# Create AWS clients
sqs_client = boto3.client('sqs')
sns_client = boto3.client('sns')

async def main():
    async with sns_sqs_server(config, sqs_client, sns_client) as (read_stream, write_stream):
        # Your MCP server logic here
        pass

Here's a basic example of implementing an MCP client which supports sns-sqs as the transport layer:

import boto3
from asyncmcp.sns_sqs.client import sns_sqs_client
from asyncmcp import SnsSqsTransportConfig

# Configure transport
config = SnsSqsTransportConfig(
    sqs_queue_url="https://sqs.region.amazonaws.com/account/client-queue",
    sns_topic_arn="arn:aws:sns:region:account:mcp-requests"
)  # more configurable params available.

# Create AWS clients
sqs_client = boto3.client('sqs')
sns_client = boto3.client('sns')

async def main():
    async with sns_sqs_client(config, sqs_client, sns_client) as (read_stream, write_stream):
        # Your MCP client logic here
        pass

You can check full examples at /examples/website_server.py and /examples/website_client.py.
Read more at /examples/README.md

  • Message Size: For SQS - message size limits are applicable (256KB standard, 2MB extended)
  • Response Handling: Async nature means responses may not be immediate
  • Session Context: Storage mechanism handled by server application, not transport
  • Ordering: Standard SQS doesn't guarantee message ordering

We welcome contributions and discussions about async MCP architectures!

git clone https://github.com/bharatgeleda/asyncmcp.git
cd asyncmcp
uv sync

Apache License 2.0 - see LICENSE file for details.

联系我们 contact @ memedata.com