validateApiKey
Verify API key validity by listing namespaces with SourceSync.ai MCP Server. Ensures secure access to knowledge management and semantic search functions.
Instructions
Validates the API key by attempting to list namespaces. Returns the list of namespaces if successful.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:111-125 (handler)Registration and inline handler implementation for the 'validateApiKey' tool. The handler validates the API key (sourced from SOURCESYNC_API_KEY environment variable) by calling listNamespaces on the SourceSync client, wrapped in safeApiCall for MCP-compatible response formatting.server.tool( 'validateApiKey', 'Validates the API key by attempting to list namespaces. Returns the list of namespaces if successful.', validateApiKeySchema.shape, async (params: ValidateApiKeyParams) => { return safeApiCall(async () => { // Create a client with the provided API key const client = createClient({}) // Validate the API key by listing namespaces // @ts-ignore - Ignoring type error for now to focus on error handling return await client.listNamespaces() }) }, )
- src/schemas.ts:110-110 (schema)Zod schema for validateApiKey tool parameters. Defined as an empty object since no input parameters are required.export const validateApiKeySchema = z.object({})
- src/schemas.ts:165-165 (schema)TypeScript type definition for ValidateApiKeyParams, inferred from the Zod schema (results in empty object type).export type ValidateApiKeyParams = z.infer<typeof validateApiKeySchema>
- src/index.ts:85-107 (helper)Helper function used by validateApiKey handler (and others) to wrap API calls, format successful responses as MCP text content, and handle errors appropriately.async function safeApiCall<T>(apiCall: () => Promise<T>) { try { const result = await apiCall() return { content: [ { type: 'text' as const, text: JSON.stringify(result), }, ], } } catch (error: any) { // Preserve the original error structure from SourceSync return { content: [ { type: 'text' as const, text: JSON.stringify(error), }, ], isError: true, } }
- src/index.ts:64-78 (helper)Helper function to create SourceSync client instance. For validateApiKey, called with empty params, so uses SOURCESYNC_API_KEY from environment.function createClient({ apiKey, namespaceId, tenantId, }: { apiKey?: string namespaceId?: string tenantId?: string }) { return sourcesync({ apiKey: apiKey || process.env.SOURCESYNC_API_KEY || '', namespaceId: namespaceId || process.env.SOURCESYNC_NAMESPACE_ID || '', tenantId: tenantId || process.env.SOURCESYNC_TENANT_ID || '', }) }