반응형

 

 

오늘은 Strands SDK 로 개발하는 Agent 의 도구에 MCP tool 을 붙여보겠다.

 

일단 MCP 도 Agent 의 하나의 tool 에 불과하다는 개념을 다시 기억하자.

 

MCP 구성은 Server 와 Client 두 가지 구현이 필요하다.

 

MCP Server 는 필요에 따라 직접 구현보다는 IDE 에서 시켜서 구현할 수 있고 ( 필자의 경우 Cursor 를 이용해서 쉽게 mcp 서버를 구현할 수 있었다.) 외부에 공개된 MCP 서버를 직접 사용할 수 있다. 다만 remote 서버의 경우 datasource 에 대한 정보들이 네트워크 트래픽을 타고 외부에 넘어갈 수 있으니 보안에 유의하자.

 

일단 아래 aws 에서도 aws 서비스에 access 할 수 있는 도구들을 mcp 서버로 제공하고 있다. 

- https://awslabs.github.io/mcp/

 

Welcome to AWS MCP Servers | AWS MCP Servers

Get started with AWS MCP Servers and learn core features.

awslabs.github.io

 

그리고 내가 일반적으로 Smithery 에서도 설치가 가능하지만, 설치가 잘 안될 때는 아래 cursor 의 mcp 페이지에서도 설치해보면 된다.

https://docs.cursor.com/ko/tools/mcp

 

Cursor: The best way to code with AI

Built to make you extraordinarily productive, Cursor is the best way to code with AI.

cursor.com

 

Strands SDK 에서의 MCP Client 요약

  • Strands SDK 에서 쉽게 MCP Client 를 구현해줌
  • MCP 클라이언트를 생성할 때 어떤 방식으로 연결할 것인지 선택해야 함
    • Standard I/O (stdio) : 로컬 프로세스를 구현한다면 적합
    • Streamable HTTP : HTTP 이벤트를 호출해서 스트림 방식으로 구현할 때
    • Server-Sent Events (SSE) : HTTP 기반의 서버를 직접 구축했을 때
    • Custom Transport with MCP Client - 그외 직접 프로토콜을 구현할 때

 

많이 활용하는 stdio , streamableHTTP 방식의 예제 코드를 아래에 첨부한다.

 

예제 코드 내용

  • Agent 모델을 만듦.
  • sequential-thingking  mcp 도구 등록.
  • strands tools 에서 기본으로 제공하는 http_request 를 이용해 openweather api 의 도큐먼트 페이지를 분석시킴.

 

from mcp import stdio_client, StdioServerParameters
from mcp.client.streamable_http import streamablehttp_client
from strands import Agent
from strands.models import BedrockModel
from strands.tools.mcp import MCPClient
from strands_tools import http_request, retrieve

base_model = BedrockModel(
    model_id="apac.anthropic.claude-3-7-sonnet-20250219-v1:0",
    region_name="ap-northeast-2",
    temperature=0.3,
)

stdio_mcp_client = MCPClient(
    lambda: stdio_client(
        StdioServerParameters(
            command="uvx",
            args=["awslabs.aws-documentation-mcp-server@latest"]
        )
    )
)

# HTTPStreamable 방식으로 붙일 경우 
# sequential_thinking = MCPClient(
#     lambda: streamablehttp_client("https://smithery.ai/server/@smithery-ai/server-sequential-thinking")
# )


# StdIO 방식으로 붙일 경우
sequential_thinking = MCPClient(
    lambda: stdio_client(
        StdioServerParameters(
            command="npx",
            args=[
                "-y",
                "@smithery/cli@latest",
                "run",
                "@smithery-ai/server-sequential-thinking",
                "--key",
                "생성된 사용자 키",
                "--profile",
                "생성된 사용자 프로필"
            ]
        )
    )
)
# 예제 테스트 코드 
with sequential_thinking:
    tools = sequential_thinking.list_tools_sync()
    tools += [http_request, retrieve]

    agent = Agent(tools=tools, model=base_model)
    result = agent("https://openweathermap.org/forecast5 에서 어떤 날씨 데이터 테이블을 수집할 수 있는지 분석해줘")
    print(result)

# with stdio_mcp_client:
#     tools = stdio_mcp_client.list_tools_sync()
#     agent = Agent(tools = tools, model = base_model)
#     result = agent("What is AWS Lambda?")
반응형

+ Recent posts