Skip to main content

커스텀 MCP 클라이언트 구축

MCP SDK를 사용하여 귀하의 애플리케이션에서 Synapse MCP 서버에 연결.


커스텀 MCP 클라이언트 구축

자체 LLM 애플리케이션을 구축하는 경우, 공식 MCP SDK를 사용하여 Synapse MCP 서버에 직접 연결할 수 있습니다. 이를 통해 앱이 79개의 모든 Synapse 도구에 접근할 수 있습니다.

SDK

언어 패키지
TypeScript/JavaScript @modelcontextprotocol/sdk
Python mcp

TypeScript 예시

설치

npm install @modelcontextprotocol/sdk

stdio를 통한 연결

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";

const transport = new StdioClientTransport({
  command: "npx",
  args: ["-y", "synapse-mcp-api@latest"],
  env: {
    SYNAPSE_MIND_KEY: process.env.SYNAPSE_MIND_KEY!,
    SYNAPSE_URL: "https://synapse.schaefer.zone",
  },
});

const client = new Client(
  { name: "my-app", version: "1.0.0" },
  { capabilities: {} }
);

await client.connect(transport);

// List all available tools
const { tools } = await client.listTools();
console.log(`Available tools: ${tools.length}`);
for (const tool of tools) {
  console.log(`- ${tool.name}: ${tool.description}`);
}

// Call a tool
const result = await client.callTool({
  name: "memory_recall",
  arguments: {},
});
console.log(result.content);

// Store a memory
await client.callTool({
  name: "memory_store",
  arguments: {
    category: "fact",
    key: "custom_client_test",
    content: "Built a custom MCP client",
    tags: ["test", "mcp"],
    priority: "normal",
  },
});

await client.close();

HTTP/SSE를 통한 연결 (원격)

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";

const transport = new SSEClientTransport(
  new URL("https://synapse-mcp.schaefer.zone/sse"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${process.env.SYNAPSE_MIND_KEY}`,
      },
    },
  }
);

const client = new Client(
  { name: "my-app", version: "1.0.0" },
  { capabilities: {} }
);

await client.connect(transport);
// ... use as above

Python 예시

설치

pip install mcp

stdio를 통한 연결

from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

server_params = StdioServerParameters(
    command="npx",
    args=["-y", "synapse-mcp-api@latest"],
    env={
        "SYNAPSE_MIND_KEY": "mk_YOUR_KEY",
        "SYNAPSE_URL": "https://synapse.schaefer.zone",
    },
)

async with stdio_client(server_params) as (read, write):
    async with ClientSession(read, write) as session:
        await session.initialize()

        # List tools
        tools = await session.list_tools()
        print(f"Available tools: {len(tools.tools)}")

        # Call a tool
        result = await session.call_tool("memory_recall", {})
        print(result.content)

        # Store a memory
        await session.call_tool("memory_store", {
            "category": "fact",
            "key": "python_client_test",
            "content": "Built a Python MCP client",
            "tags": ["test", "mcp", "python"],
            "priority": "normal",
        })

도구 프로필

연결 시, Mcp-Tool-Profile 헤더 (HTTP/SSE) 또는 MCP_PROFILE 환경 변수 (stdio)를 통해 특정 도구 프로필을 요청할 수 있습니다:

// stdio: set env var
env: {
  SYNAPSE_MIND_KEY: "mk_...",
  MCP_PROFILE: "minimal",  // 8 tools instead of 119
}

// HTTP/SSE: set header
requestInit: {
  headers: {
    Authorization: "Bearer mk_...",
    "Mcp-Tool-Profile": "minimal",
  },
}

오류 처리

try {
  const result = await client.callTool({ name: "memory_recall", arguments: {} });
  if (result.isError) {
    console.error("Tool error:", result.content);
  } else {
    console.log("Success:", result.content);
  }
} catch (err) {
  console.error("MCP error:", err);
}

사용 사례

  • 커스텀 AI 어시스턴트 — 영구 메모리가 있는 자체 에이전트 구축
  • 워크플로우 자동화 — 커스텀 워크플로우에서 Synapse 도구 체인
  • 데이터 파이프라인 — 메모리 추출, 변환, 다른 곳에 로드
  • 모니터링 대시보드 — 메모리 통계, 채팅 기록, 작업 표시

다음 단계