MCP client adapter that joins external MCP server tools into the Spakky Agent tool catalog
Project description
spakky-mcp
MCP(Model Context Protocol) 양방향 어댑터 플러그인입니다. 클라이언트 방향은 외부 MCP 서버의 도구를 발견해 Spakky Agent 도구 카탈로그에 합류시키고, 서버 방향은 Agent의 @agent_tool 도구를 MCP 서버로 노출해 외부 MCP 클라이언트가 발견·호출하게 합니다. 양쪽 모두 @agent_tool로 선언한 도구와 동일한 디스패치 경로(AgentToolDispatcher)로 실행됩니다.
ADR-0013 §2에 따라 코어(spakky-agent)는 MCP 라이브러리에 의존하지 않으며, 외부 도구 정규화·연결 수명주기와 도구의 MCP 서버 노출은 이 어댑터가 전담합니다.
언제 필요한가
- 클라이언트: 운영 중인 외부 MCP 서버의 도구를 에이전트가 일반 도구처럼 사용하고 싶을 때.
- 서버: 에이전트의 도구를 외부 MCP 클라이언트(다른 에이전트·IDE·MCP 호스트)에 표준 프로토콜로 노출하고 싶을 때.
이 플러그인은 도구 공급원/노출원이며 모델 어댑터가 아닙니다 — 에이전트 실행에는 별도의 IAgentModel 공급자(예: spakky-vllm)가 필요합니다.
설치
uv add spakky-mcp
# 또는 에이전트 번들로
uv add "spakky[agent]"
설정
외부 서버는 SPAKKY_MCP__ 접두사 환경변수 또는 McpConfig로 선언합니다.
| 환경변수 | 의미 | 기본값 |
|---|---|---|
SPAKKY_MCP__SERVERS |
외부 MCP 서버 목록(JSON 배열) | [] |
SPAKKY_MCP__CONNECT_TIMEOUT_SECONDS |
연결 수립 타임아웃(초) | 30.0 |
서버 항목은 name, transport(stdio 또는 streamable_http), command/args/env(stdio), url(streamable_http), call_timeout_seconds를 가집니다. name은 도구 이름 충돌을 막는 접두사로 쓰이며 __를 포함할 수 없습니다.
도구를 MCP 서버로 노출할 때의 식별자·전송은 SPAKKY_MCP__TOOL_SERVER__NAME(기본 spakky-agent)·SPAKKY_MCP__TOOL_SERVER__TRANSPORT(기본 stdio)로 선언합니다.
initialize()는 McpConfig, McpClient, McpToolServer를 application container에 등록합니다.
사용
클라이언트: 외부 도구 끌어오기
from spakky.plugins.mcp import McpClient
async def run_with_external_tools(client: McpClient, agent: object) -> None:
# 선언된 외부 서버에 연결하고, 외부 도구를 카탈로그에 더한 runner를 받는다.
async with client.open_runner(agent) as runner:
async for item in runner.run(run_input):
... # 외부 도구가 native @agent_tool 도구와 같은 경로로 디스패치된다
모델이 보는 외부 도구 이름은 <서버이름>__<도구이름> 형태로 접두사가 붙어 서버 간 이름 충돌을 막습니다.
McpClient.open_runner()는 지정된 서버들의 transport session을 열고 list_tools() 결과를 AgentToolDescriptor로 정규화한 뒤, native catalog와 external catalog를 합친 runner를 yield합니다. 이 runner는 context manager가 살아 있는 동안만 외부 도구 callable이 유효합니다. ExternalMcpToolDescriptor는 MCP argument object를 그대로 keyword argument로 전달하므로 MCP schema가 args 또는 kwargs라는 필드를 선언해도 Spakky의 structured-call binding heuristic에 의해 손실되지 않습니다.
서버: 자신의 도구 내보내기
from spakky.plugins.mcp import McpToolServer
async def expose_tools(server: McpToolServer, agent: object) -> None:
# 에이전트의 @agent_tool 도구를 stdio MCP 서버로 노출한다.
await server.serve_stdio(agent)
원격 노출에는 McpToolServer.streamable_http_session_manager(agent)가 돌려주는 세션 매니저를 호스트 애플리케이션 lifespan에서 구동합니다.
서버 방향은 agent의 AgentToolCatalog를 mcp.types.Tool 목록으로 변환하고, inbound call_tool을 AgentToolDispatcher로 실행합니다. 반환값은 MCP content와 structuredContent로 정규화됩니다. mapping 결과는 structured payload 그대로 노출하고, scalar 결과는 {"result": ...}로 감싸서 항상 JSON object structured content를 제공합니다.
자세한 내용은 MCP 어댑터 가이드를 참고하세요.
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spakky_mcp-6.10.1.tar.gz.
File metadata
- Download URL: spakky_mcp-6.10.1.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
190f4678db4461610e450d256268b58376aac64c689ae69ecaebfa9d47b7d4e4
|
|
| MD5 |
d648e06f38994e677280262caf78fe29
|
|
| BLAKE2b-256 |
43d36630a6a1cfacf6aa2b431d689178a78d5c08edb4a9700794f083d6a963a2
|
Provenance
The following attestation bundles were made for spakky_mcp-6.10.1.tar.gz:
Publisher:
release.yml on E5presso/spakky-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spakky_mcp-6.10.1.tar.gz -
Subject digest:
190f4678db4461610e450d256268b58376aac64c689ae69ecaebfa9d47b7d4e4 - Sigstore transparency entry: 1963006978
- Sigstore integration time:
-
Permalink:
E5presso/spakky-framework@8adc66b2fd54c8fc3c51f6f166b68f6bcc2fcc0f -
Branch / Tag:
refs/heads/develop - Owner: https://github.com/E5presso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8adc66b2fd54c8fc3c51f6f166b68f6bcc2fcc0f -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file spakky_mcp-6.10.1-py3-none-any.whl.
File metadata
- Download URL: spakky_mcp-6.10.1-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7209e49d6e8133631bd1b7449b2221feefa71e06b5eda75c9b1fdf4bafa492bc
|
|
| MD5 |
47eea267c3c76668b25b6ee840085b72
|
|
| BLAKE2b-256 |
d523df536f7d078498325ad63ff5615742bec0c85ceb6a66a8597bb588da473c
|
Provenance
The following attestation bundles were made for spakky_mcp-6.10.1-py3-none-any.whl:
Publisher:
release.yml on E5presso/spakky-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spakky_mcp-6.10.1-py3-none-any.whl -
Subject digest:
7209e49d6e8133631bd1b7449b2221feefa71e06b5eda75c9b1fdf4bafa492bc - Sigstore transparency entry: 1963007079
- Sigstore integration time:
-
Permalink:
E5presso/spakky-framework@8adc66b2fd54c8fc3c51f6f166b68f6bcc2fcc0f -
Branch / Tag:
refs/heads/develop - Owner: https://github.com/E5presso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8adc66b2fd54c8fc3c51f6f166b68f6bcc2fcc0f -
Trigger Event:
workflow_dispatch
-
Statement type: