deepsource-mcp-server
Version:
Model Context Protocol server for DeepSource
74 lines (73 loc) • 2.08 kB
TypeScript
/**
* @fileoverview Response builder utility for MCP tool handlers.
* Provides a consistent way to build tool responses with proper error handling.
* @packageDocumentation
*/
/**
* Response structure for MCP tools
*/
export interface ToolResponse {
content: Array<{
type: 'text';
text: string;
}>;
structuredContent?: unknown;
isError: boolean;
}
/**
* Options for building a response
*/
export interface ResponseBuilderOptions {
/** Whether to log the response */
log?: boolean;
/** Tool name for logging */
toolName?: string;
/** Structured content to include */
structuredContent?: unknown;
}
/**
* Builder class for creating consistent tool responses
*/
export declare class ToolResponseBuilder {
private content;
private isError;
private structuredContent?;
private options;
constructor(options?: ResponseBuilderOptions);
/**
* Create a success response builder
*/
static success(data: unknown, options?: ResponseBuilderOptions): ToolResponseBuilder;
/**
* Create an error response builder
*/
static error(error: Error | string, options?: ResponseBuilderOptions): ToolResponseBuilder;
/**
* Add data to the response
*/
withData(data: unknown): this;
/**
* Add an error to the response
*/
withError(error: Error | string): this;
/**
* Set structured content
*/
withStructuredContent(content: unknown): this;
/**
* Build the final response
*/
build(): ToolResponse;
}
/**
* Helper function to create a success response
*/
export declare function successResponse(data: unknown, options?: ResponseBuilderOptions): ToolResponse;
/**
* Helper function to create an error response
*/
export declare function errorResponse(error: Error | string, options?: ResponseBuilderOptions): ToolResponse;
/**
* Helper function to parse and validate a tool response
*/
export declare function parseToolResponse<T = unknown>(response: ToolResponse, validator?: (data: unknown) => data is T): T;