graphql-agent-toolkit 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,260 @@
1
+ import { IntrospectionQuery } from 'graphql';
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { z } from 'zod';
4
+
5
+ interface SchemaField {
6
+ name: string;
7
+ description: string | null;
8
+ type: TypeRef;
9
+ args: SchemaArgument[];
10
+ isDeprecated: boolean;
11
+ }
12
+ interface SchemaArgument {
13
+ name: string;
14
+ description: string | null;
15
+ type: TypeRef;
16
+ defaultValue: string | null;
17
+ }
18
+ interface TypeRef {
19
+ kind: 'SCALAR' | 'OBJECT' | 'INTERFACE' | 'UNION' | 'ENUM' | 'INPUT_OBJECT' | 'LIST' | 'NON_NULL';
20
+ name: string | null;
21
+ ofType: TypeRef | null;
22
+ }
23
+ interface SchemaType {
24
+ name: string;
25
+ kind: TypeRef['kind'];
26
+ description: string | null;
27
+ fields: SchemaField[];
28
+ inputFields: SchemaArgument[];
29
+ enumValues: {
30
+ name: string;
31
+ description: string | null;
32
+ }[];
33
+ interfaces: string[];
34
+ possibleTypes: string[];
35
+ }
36
+ interface ParsedSchema {
37
+ queryType: string;
38
+ mutationType: string | null;
39
+ subscriptionType: string | null;
40
+ types: Map<string, SchemaType>;
41
+ }
42
+ interface AgentToolkitConfig {
43
+ endpoint: string;
44
+ headers?: Record<string, string>;
45
+ operationDepth?: number;
46
+ includeDeprecated?: boolean;
47
+ }
48
+
49
+ interface FetchSchemaOptions {
50
+ endpoint: string;
51
+ headers?: Record<string, string>;
52
+ }
53
+ declare function fetchSchema(options: FetchSchemaOptions): Promise<IntrospectionQuery>;
54
+
55
+ declare function parseSchema(introspectionResult: IntrospectionQuery): ParsedSchema;
56
+
57
+ interface VariableDefinition {
58
+ name: string;
59
+ type: string;
60
+ required: boolean;
61
+ description: string | null;
62
+ }
63
+ interface GeneratedOperation {
64
+ operation: string;
65
+ operationName: string;
66
+ variables: VariableDefinition[];
67
+ operationType: 'query' | 'mutation';
68
+ }
69
+ interface BuildOperationOptions {
70
+ maxDepth?: number;
71
+ includeDeprecated?: boolean;
72
+ }
73
+ declare function buildOperation(schema: ParsedSchema, rootFieldName: string, options?: BuildOperationOptions): GeneratedOperation;
74
+
75
+ interface AgentToolkitServerOptions {
76
+ serverName?: string;
77
+ serverVersion?: string;
78
+ }
79
+ /**
80
+ * Creates a fully configured MCP server from a GraphQL endpoint configuration.
81
+ */
82
+ declare function createAgentToolkitServer(config: AgentToolkitConfig, options?: AgentToolkitServerOptions): Promise<McpServer>;
83
+
84
+ declare class GraphQLExecutor {
85
+ private client;
86
+ constructor(endpoint: string, headers?: Record<string, string>);
87
+ execute(operation: string, variables?: Record<string, unknown>, additionalHeaders?: Record<string, string>): Promise<string>;
88
+ }
89
+
90
+ interface McpToolDefinition {
91
+ name: string;
92
+ description: string;
93
+ inputSchema: Record<string, z.ZodType>;
94
+ execute: (args: Record<string, unknown>) => Promise<string>;
95
+ }
96
+ interface CreateToolsOptions {
97
+ maxDepth?: number;
98
+ includeDeprecated?: boolean;
99
+ }
100
+ /**
101
+ * Creates MCP tool definitions from a parsed GraphQL schema.
102
+ */
103
+ declare function createToolsFromSchema(schema: ParsedSchema, executor: GraphQLExecutor, options?: CreateToolsOptions): McpToolDefinition[];
104
+
105
+ interface SearchResult {
106
+ typeName: string;
107
+ score: number;
108
+ kind: string;
109
+ description: string | null;
110
+ }
111
+ /**
112
+ * SchemaNavigator provides semantic search over a GraphQL schema
113
+ * using TF-IDF and cosine similarity.
114
+ */
115
+ declare class SchemaNavigator {
116
+ private schema;
117
+ private documents;
118
+ private idf;
119
+ /**
120
+ * Index a parsed schema for semantic search.
121
+ */
122
+ index(schema: ParsedSchema): void;
123
+ /**
124
+ * Search the schema for types matching the query.
125
+ */
126
+ search(query: string, limit?: number): SearchResult[];
127
+ /**
128
+ * Get formatted context for a specific type.
129
+ */
130
+ getTypeContext(typeName: string): string | null;
131
+ private computeIdf;
132
+ private computeTfidf;
133
+ private cosineSimilarity;
134
+ }
135
+
136
+ interface PaginationConfig {
137
+ style: 'relay' | 'offset' | 'auto';
138
+ pageSize: number;
139
+ maxPages?: number;
140
+ }
141
+ interface PaginatedResult<T = unknown> {
142
+ items: T[];
143
+ totalFetched: number;
144
+ hasMore: boolean;
145
+ cursors?: {
146
+ start: string;
147
+ end: string;
148
+ };
149
+ }
150
+ /**
151
+ * Auto-detect pagination style from a type's fields.
152
+ *
153
+ * Relay: The type has an `edges` field whose unwrapped type has a `node` field,
154
+ * AND a `pageInfo` field whose type has `hasNextPage` and `endCursor`.
155
+ *
156
+ * Offset: The type (or its parent query field) has `limit`/`offset` or `skip`/`take` args.
157
+ * We detect this by looking for fields on the Query type that return this typeName
158
+ * and have offset-style arguments.
159
+ */
160
+ declare function detectPaginationStyle(schema: ParsedSchema, typeName: string): 'relay' | 'offset' | 'none';
161
+ /**
162
+ * Execute a paginated query, collecting all pages.
163
+ */
164
+ declare function executePaginated(executor: GraphQLExecutor, operation: string, variables: Record<string, unknown>, config?: PaginationConfig): Promise<PaginatedResult>;
165
+
166
+ interface SummaryConfig {
167
+ maxItems: number;
168
+ maxDepth: number;
169
+ maxStringLength: number;
170
+ includeMetadata: boolean;
171
+ }
172
+ interface SummaryMetadata {
173
+ totalItems: number;
174
+ truncated: boolean;
175
+ originalSize: number;
176
+ }
177
+ /**
178
+ * Summarize a GraphQL response by truncating arrays, limiting depth,
179
+ * and shortening long strings.
180
+ */
181
+ declare function summarizeResponse(data: unknown, config?: Partial<SummaryConfig>): {
182
+ summary: unknown;
183
+ metadata: SummaryMetadata;
184
+ };
185
+ /**
186
+ * Format data as clean markdown suitable for LLM context.
187
+ */
188
+ declare function formatForLLM(data: unknown, config?: Partial<SummaryConfig>): string;
189
+
190
+ interface LangChainToolConfig {
191
+ name: string;
192
+ description: string;
193
+ schema: Record<string, unknown>;
194
+ func: (input: string) => Promise<string>;
195
+ }
196
+ interface StructuredToolConfig {
197
+ name: string;
198
+ description: string;
199
+ schema: z.ZodObject<Record<string, z.ZodType>>;
200
+ func: (input: Record<string, unknown>) => Promise<string>;
201
+ }
202
+ interface AdapterOptions$2 {
203
+ maxDepth?: number;
204
+ }
205
+ /**
206
+ * Create tools compatible with LangChain's Tool pattern.
207
+ * Each tool's func accepts a JSON string input and returns a JSON string.
208
+ */
209
+ declare function createLangChainTools(schema: ParsedSchema, executor: GraphQLExecutor, options?: AdapterOptions$2): LangChainToolConfig[];
210
+ /**
211
+ * Create tools compatible with LangChain's StructuredTool pattern.
212
+ * Each tool's func accepts a typed object and returns a JSON string.
213
+ */
214
+ declare function createStructuredTools(schema: ParsedSchema, executor: GraphQLExecutor, options?: AdapterOptions$2): StructuredToolConfig[];
215
+
216
+ interface CrewAIToolConfig {
217
+ name: string;
218
+ description: string;
219
+ args_schema: Record<string, unknown>;
220
+ func: (args: Record<string, unknown>) => Promise<string>;
221
+ }
222
+ interface AdapterOptions$1 {
223
+ maxDepth?: number;
224
+ }
225
+ /**
226
+ * Create tools compatible with CrewAI's tool interface.
227
+ * CrewAI uses args_schema (JSON Schema) and func takes a dict.
228
+ */
229
+ declare function createCrewAITools(schema: ParsedSchema, executor: GraphQLExecutor, options?: AdapterOptions$1): CrewAIToolConfig[];
230
+
231
+ interface VercelAIToolConfig {
232
+ description: string;
233
+ parameters: z.ZodObject<Record<string, z.ZodType>>;
234
+ execute: (args: Record<string, unknown>) => Promise<string>;
235
+ }
236
+ interface AdapterOptions {
237
+ maxDepth?: number;
238
+ }
239
+ /**
240
+ * Create tools compatible with Vercel AI SDK's tool() shape.
241
+ * Returns Record<toolName, { description, parameters: ZodSchema, execute }>.
242
+ */
243
+ declare function createVercelAITools(schema: ParsedSchema, executor: GraphQLExecutor, options?: AdapterOptions): Record<string, VercelAIToolConfig>;
244
+
245
+ interface MockConfig {
246
+ seed?: number;
247
+ arrayLength?: number;
248
+ maxDepth?: number;
249
+ }
250
+ /**
251
+ * Generate mock data for a specific type in the schema.
252
+ */
253
+ declare function generateMockData(schema: ParsedSchema, typeName: string, config?: MockConfig): Record<string, unknown>;
254
+ /**
255
+ * Create a mock executor that returns generated data instead of HTTP calls.
256
+ * Implements the same interface as GraphQLExecutor.
257
+ */
258
+ declare function createMockExecutor(schema: ParsedSchema, config?: MockConfig): GraphQLExecutor;
259
+
260
+ export { type AgentToolkitConfig, type CrewAIToolConfig, type GeneratedOperation, GraphQLExecutor, type LangChainToolConfig, type MockConfig, type PaginatedResult, type PaginationConfig, type ParsedSchema, type SchemaArgument, type SchemaField, SchemaNavigator, type SchemaType, type SearchResult, type StructuredToolConfig, type SummaryConfig, type SummaryMetadata, type TypeRef, type VariableDefinition, type VercelAIToolConfig, buildOperation, createAgentToolkitServer, createCrewAITools, createLangChainTools, createMockExecutor, createStructuredTools, createToolsFromSchema, createVercelAITools, detectPaginationStyle, executePaginated, fetchSchema, formatForLLM, generateMockData, parseSchema, summarizeResponse };