amazon-seller-mcp
Version:
Model Context Protocol (MCP) client for Amazon Selling Partner API
269 lines (268 loc) • 6.96 kB
TypeScript
/**
* Amazon Seller MCP Server implementation
*
* This file implements the MCP server for Amazon Selling Partner API
* using the Model Context Protocol SDK.
*/
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { AmazonRegion, AmazonCredentials } from '../types/auth.js';
import { ResourceRegistrationManager } from './resources.js';
import { ToolRegistrationManager, ToolRegistrationOptions, ToolHandler } from './tools.js';
import { NotificationManager } from './notifications.js';
import { CacheConfig } from '../utils/cache-manager.js';
import { ConnectionPoolConfig } from '../utils/connection-pool.js';
/**
* Configuration for the Amazon Seller MCP Server
*/
export interface AmazonSellerMcpConfig {
/**
* Server name
*/
name: string;
/**
* Server version
*/
version: string;
/**
* Amazon Selling Partner API credentials
*/
credentials: AmazonCredentials;
/**
* Amazon marketplace ID
*/
marketplaceId: string;
/**
* Amazon region
*/
region: AmazonRegion;
/**
* Whether to debounce notifications
*/
debouncedNotifications?: boolean;
/**
* Cache configuration
*/
cacheConfig?: CacheConfig;
/**
* Connection pool configuration
*/
connectionPoolConfig?: ConnectionPoolConfig;
}
/**
* Transport configuration for the MCP server
*/
export interface TransportConfig {
/**
* Transport type
*/
type: 'stdio' | 'streamableHttp';
/**
* HTTP options (required if type is 'streamableHttp')
*/
httpOptions?: {
/**
* HTTP port
*/
port: number;
/**
* HTTP host
*/
host: string;
/**
* Whether to enable DNS rebinding protection
*/
enableDnsRebindingProtection?: boolean;
/**
* Allowed hosts for CORS
*/
allowedHosts?: string[];
/**
* Whether to enable session management
*/
sessionManagement?: boolean;
};
}
/**
* Amazon Seller MCP Server class
* Implements the MCP protocol for Amazon Selling Partner API
*/
export declare class AmazonSellerMcpServer {
/**
* MCP server instance
*/
private server;
/**
* Server configuration
*/
private config;
/**
* Transport instance
*/
private transport;
/**
* HTTP server instance (for streamableHttp transport)
*/
private httpServer;
/**
* Map to store transports by session ID (for streamableHttp)
*/
private transports;
/**
* Whether the server is connected
*/
private isConnected;
/**
* Resource registration manager
*/
private resourceManager;
/**
* Tool registration manager
*/
private toolManager;
/**
* Notification manager
*/
private notificationManager;
/**
* Validates the server configuration
* @param config Server configuration to validate
* @throws Error if configuration is invalid
*/
private validateConfiguration;
/**
* Creates a new instance of the Amazon Seller MCP Server
* @param config Server configuration
*/
constructor(config: AmazonSellerMcpConfig);
/**
* Connects the server to the specified transport
* @param transportConfig Transport configuration
*/
connect(transportConfig: TransportConfig): Promise<void>;
/**
* Sets up HTTP transport with proper request handling
*/
private setupHttpTransport;
/**
* Handles HTTP requests for streamable transport
*/
private handleHttpRequest;
/**
* Handles MCP JSON-RPC requests
*/
private handleMcpRequest;
/**
* Checks if a request is an initialize request
*/
private isInitializeRequest;
/**
* Registers all available tools
*/
registerAllTools(): Promise<void>;
/**
* Registers catalog tools
*/
private registerCatalogTools;
/**
* Registers listings tools
*/
private registerListingsTools;
/**
* Registers inventory tools
*/
private registerInventoryTools;
/**
* Registers orders tools
*/
private registerOrdersTools;
/**
* Registers reports tools
*/
private registerReportsTools;
/**
* Registers AI-assisted tools
*/
private registerAiTools;
/**
* Registers a tool with the MCP server
*
* @param name Tool name
* @param options Tool registration options
* @param handler Tool handler function
* @returns True if the tool was registered, false if it was already registered
*/
registerTool<T = unknown>(name: string, options: ToolRegistrationOptions, handler: ToolHandler<T>): boolean;
/**
* Gets the tool registration manager
*/
getToolManager(): ToolRegistrationManager;
/**
* Gets the notification manager
*/
getNotificationManager(): NotificationManager;
/**
* Registers all available resources
*/
registerAllResources(): Promise<void>;
/**
* Registers catalog resources
*/
private registerCatalogResources;
/**
* Registers listings resources
*/
private registerListingsResources;
/**
* Registers inventory resources
*/
private registerInventoryResources;
/**
* Registers orders resources
*/
private registerOrdersResources;
/**
* Registers reports resources
*/
private registerReportsResources;
/**
* Registers a resource with the MCP server
*
* @param name Resource name
* @param uriTemplate URI template string
* @param options Resource registration options
* @param handler Resource handler function
* @param listTemplate Optional list template string
* @param completions Optional completions configuration
* @returns True if the resource was registered, false if it was already registered
*/
registerResource(name: string, uriTemplate: string, options: {
title: string;
description: string;
}, handler: (uri: URL, params: Record<string, string>) => Promise<{
contents: Array<{
uri: string;
text: string;
mimeType?: string;
}>;
}>, listTemplate?: string, completions?: Record<string, (value: string) => Promise<string[]>>): boolean;
/**
* Gets the resource registration manager
*/
getResourceManager(): ResourceRegistrationManager;
/**
* Closes the server and cleans up resources
*/
close(): Promise<void>;
/**
* Checks if the server is connected
*/
isServerConnected(): boolean;
/**
* Gets the MCP server instance
*/
getMcpServer(): McpServer;
/**
* Gets the server configuration
*/
getConfig(): AmazonSellerMcpConfig;
}