McpContentBlock class
MCP 도구 응답 콘텐츠 블록을 위한 추상 기본 클래스.
Azure Functions 라이브러리는 콘텐츠를 블록과 일반 사용자 값을 구instanceof McpContentBlock별하므로, 내장 서브클래스(McpTextContent, , McpResourceLinkContentMcpImageContentMcpAudioContentMcpResourceContent, , ) 인스턴스 — 또는 이 클래스를 확장한 사용자 정의 서브클래스 — 만 콘텐츠 블록으로 취급됩니다.
일반 객체 리터럴 { type: 'text', text: '...' } 은 콘텐츠 블록으로 취급 되지 않고 JSON 텍스트로 직렬화됩니다.
사용자 지정 콘텐츠 블록 유형으로 확장
MCP 사양에 새로운 블록 타입이 추가되거나 시나리오에 커스텀 블록이 필요하다면, 라이브러리 변경 없이 자신만의 서브클래스를 출시할 수 있습니다. 변환기는 검사만 하고 instanceof McpContentBlock 호출 JSON.stringify(block)하여 와이어 페이로드를 생성하도록 요청 toJSON() 합니다.
예시: 가상의 추가 VideoContent
import { McpContentBlock } from '@azure/functions';
export interface VideoContentInit {
data: string | Buffer | ArrayBuffer;
mimeType: string; // e.g. 'video/mp4'
durationMs?: number; // optional field from a hypothetical spec
}
export class VideoContent extends McpContentBlock {
readonly type = 'video' as const;
readonly data: string | Buffer | ArrayBuffer;
readonly mimeType: string;
readonly durationMs?: number;
constructor(init: VideoContentInit) {
super();
this.data = init.data;
this.mimeType = init.mimeType;
this.durationMs = init.durationMs;
}
toJSON(): Record<string, unknown> {
const out: Record<string, unknown> = {
type: this.type,
data: toBase64(this.data),
mimeType: this.mimeType,
};
if (this.durationMs !== undefined) out.durationMs = this.durationMs;
return out;
}
}
function toBase64(data: string | Buffer | ArrayBuffer): string {
if (typeof data === 'string') return data;
if (Buffer.isBuffer(data)) return data.toString('base64');
return Buffer.from(new Uint8Array(data)).toString('base64');
}
툴 핸들러에서 사용자 지정 블록 사용하기
// Single block
handler: async () => new VideoContent({ data: buf, mimeType: 'video/mp4' })
// Mixed with built-ins + structured content
handler: async () => new McpToolResponse({
content: [
new McpTextContent('Detected 3 scenes'),
new VideoContent({ data: buf, mimeType: 'video/mp4' }),
],
structuredContent: { scenes: 3, confidence: 0.92 },
})
도서관이 당신을 위해 하는 일들
-
instanceof McpContentBlock당신의 서브클래스를 내장 블록과 동일하게 취급합니다. - 단일 블록 반환은 문자열을 외부 결과로 전파하며
type, 배열은 로 랩됩니다multi_content_result. -
structuredContent처리, 대체 텍스트 합성, 그리고 nullish 패스스루는 모두 변경 없이 적용됩니다.
서브클래스에서 반드시 제대로 해야 할 것들
-
toJSON()귀하의 . 사양에서 요구하는type정확한 와이어 형태를 반드시 반납해야 합니다. - 바이너리 페이로드는 base64로 인코딩
toJSON()되어야 합니다(위의 헬퍼 참조toBase64). - 일반 객체 리터럴은 인식 되지 않습니다 — 인스턴스를 생성해야 합니다.
속성
| type |
메서드
| toJSON() |
속성 세부 정보
type
type: string
속성 값
string
메서드 세부 정보
toJSON()
function toJSON(): Record<string, unknown>
반품
Record<string, unknown>