MCP Structured Output 검증기
코딩중급
outputSchema를 선언해 도구 출력을 자동 검증하고, 사람이 읽을 수 있는 content와 기계가 파싱할 수 있는 structuredContent를 동시에 제공합니다.
트리거
/mcp-output-schema사용빈도per tool
MCP Server Author라면? Use /mcp-output-schema to add type-safe outputs to your tools
Integration Developer라면? Ensure downstream systems can parse tool results reliably
MCPStructured OutputJSON Schema검증
작동 흐름
/mcp-output-schema [tool-name] run
↓
Phase 1: analyze tool output
output-analysis
Infer schema from current tool responses
schema-gen
Generate outputSchema definition
validator
Create runtime validation layer
↓
Wire schema into tool definition
↓
✓ Tool with outputSchema + structuredContent validation
스킬 코드
# MCP Structured Output Validator
## Trigger: /mcp-output-schema [tool-name]
When invoked:
1. Define outputSchema on tool registration:
```typescript
server.tool(
"get-weather",
{
description: "Get current weather for a city",
inputSchema: {
type: "object",
properties: {
city: { type: "string" }
},
required: ["city"]
},
// NEW: declare structured output schema
outputSchema: {
type: "object",
properties: {
temperature: { type: "number" },
unit: { type: "string", enum: ["celsius", "fahrenheit"] },
condition: { type: "string" },
humidity: { type: "number" }
},
required: ["temperature", "unit", "condition"]
}
},
async ({ city }) => {
const data = await fetchWeather(city);
return {
// Human-readable content (always present)
content: [{
type: "text",
text: `It's ${data.temp}°C and ${data.condition} in ${city}`
}],
// Machine-readable structured output (validated against outputSchema)
structuredContent: {
temperature: data.temp,
unit: "celsius",
condition: data.condition,
humidity: data.humidity
}
};
}
);
```
2. Validation behavior:
- Server SDK auto-validates structuredContent against outputSchema
- Schema violations throw at runtime (fail-fast)
- structuredContent MUST be present when outputSchema is defined
- content[] is still required for human-readable fallback
3. Client consumption:
```typescript
const result = await client.callTool("get-weather", { city: "Seoul" });
// Type-safe access to structured data
const temp = result.structuredContent.temperature; // number
const condition = result.structuredContent.condition; // string
```
복사해서 CLAUDE.md에 붙여넣으면 바로 사용할 수 있습니다.
MCP Structured Output 검증기 작동 방식
MCP Structured Output Validator는 기존 tool의 응답 패턴을 분석하여 outputSchema를 추론·생성하고, structuredContent가 스키마를 준수하는지 런타임 검증 레이어를 추가합니다. 사람이 읽는 content[]와 기계가 소비하는 structuredContent를 동시에 제공하는 이중 출력 구조를 보장합니다.
MCP Structured Output 검증기이(가) 빛나는 순간
MCP tool의 결과를 다른 시스템이 프로그래밍 방식으로 안정적으로 소비해야 할 때, 또는 tool 응답의 타입 안전성을 보장하고 싶을 때 가장 강력합니다.
핵심 특장점
- outputSchema 자동 추론 및 생성
- 런타임 스키마 검증으로 fail-fast 보장
- human-readable + machine-readable 이중 출력
- 다운스트림 시스템 통합 안정성 확보