profound-mcp 0.2.1

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.
Files changed (270) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +231 -0
  3. package/code-tool-paths.cjs +6 -0
  4. package/code-tool-paths.cjs.map +1 -0
  5. package/code-tool-paths.d.cts +2 -0
  6. package/code-tool-paths.d.cts.map +1 -0
  7. package/code-tool-types.d.mts +14 -0
  8. package/code-tool-types.d.mts.map +1 -0
  9. package/code-tool-types.d.ts +14 -0
  10. package/code-tool-types.d.ts.map +1 -0
  11. package/code-tool-types.js +4 -0
  12. package/code-tool-types.js.map +1 -0
  13. package/code-tool-types.mjs +3 -0
  14. package/code-tool-types.mjs.map +1 -0
  15. package/code-tool-worker.d.mts +5 -0
  16. package/code-tool-worker.d.mts.map +1 -0
  17. package/code-tool-worker.d.ts +5 -0
  18. package/code-tool-worker.d.ts.map +1 -0
  19. package/code-tool-worker.js +45 -0
  20. package/code-tool-worker.js.map +1 -0
  21. package/code-tool-worker.mjs +40 -0
  22. package/code-tool-worker.mjs.map +1 -0
  23. package/code-tool.d.mts +12 -0
  24. package/code-tool.d.mts.map +1 -0
  25. package/code-tool.d.ts +12 -0
  26. package/code-tool.d.ts.map +1 -0
  27. package/code-tool.js +157 -0
  28. package/code-tool.js.map +1 -0
  29. package/code-tool.mjs +121 -0
  30. package/code-tool.mjs.map +1 -0
  31. package/compat.d.mts +58 -0
  32. package/compat.d.mts.map +1 -0
  33. package/compat.d.ts +58 -0
  34. package/compat.d.ts.map +1 -0
  35. package/compat.js +387 -0
  36. package/compat.js.map +1 -0
  37. package/compat.mjs +378 -0
  38. package/compat.mjs.map +1 -0
  39. package/docs-search-tool.d.mts +44 -0
  40. package/docs-search-tool.d.mts.map +1 -0
  41. package/docs-search-tool.d.ts +44 -0
  42. package/docs-search-tool.d.ts.map +1 -0
  43. package/docs-search-tool.js +43 -0
  44. package/docs-search-tool.js.map +1 -0
  45. package/docs-search-tool.mjs +39 -0
  46. package/docs-search-tool.mjs.map +1 -0
  47. package/dynamic-tools.d.mts +12 -0
  48. package/dynamic-tools.d.mts.map +1 -0
  49. package/dynamic-tools.d.ts +12 -0
  50. package/dynamic-tools.d.ts.map +1 -0
  51. package/dynamic-tools.js +135 -0
  52. package/dynamic-tools.js.map +1 -0
  53. package/dynamic-tools.mjs +132 -0
  54. package/dynamic-tools.mjs.map +1 -0
  55. package/filtering.d.mts +2 -0
  56. package/filtering.d.mts.map +1 -0
  57. package/filtering.d.ts +2 -0
  58. package/filtering.d.ts.map +1 -0
  59. package/filtering.js +20 -0
  60. package/filtering.js.map +1 -0
  61. package/filtering.mjs +13 -0
  62. package/filtering.mjs.map +1 -0
  63. package/headers.d.mts +4 -0
  64. package/headers.d.mts.map +1 -0
  65. package/headers.d.ts +4 -0
  66. package/headers.d.ts.map +1 -0
  67. package/headers.js +10 -0
  68. package/headers.js.map +1 -0
  69. package/headers.mjs +6 -0
  70. package/headers.mjs.map +1 -0
  71. package/http.d.mts +9 -0
  72. package/http.d.mts.map +1 -0
  73. package/http.d.ts +9 -0
  74. package/http.d.ts.map +1 -0
  75. package/http.js +108 -0
  76. package/http.js.map +1 -0
  77. package/http.mjs +100 -0
  78. package/http.mjs.map +1 -0
  79. package/index.d.mts +3 -0
  80. package/index.d.mts.map +1 -0
  81. package/index.d.ts +3 -0
  82. package/index.d.ts.map +1 -0
  83. package/index.js +91 -0
  84. package/index.js.map +1 -0
  85. package/index.mjs +89 -0
  86. package/index.mjs.map +1 -0
  87. package/options.d.mts +20 -0
  88. package/options.d.mts.map +1 -0
  89. package/options.d.ts +20 -0
  90. package/options.d.ts.map +1 -0
  91. package/options.js +424 -0
  92. package/options.js.map +1 -0
  93. package/options.mjs +417 -0
  94. package/options.mjs.map +1 -0
  95. package/package.json +216 -0
  96. package/server.d.mts +35 -0
  97. package/server.d.mts.map +1 -0
  98. package/server.d.ts +35 -0
  99. package/server.d.ts.map +1 -0
  100. package/server.js +174 -0
  101. package/server.js.map +1 -0
  102. package/server.mjs +160 -0
  103. package/server.mjs.map +1 -0
  104. package/src/code-tool-paths.cts +3 -0
  105. package/src/code-tool-types.ts +14 -0
  106. package/src/code-tool-worker.ts +46 -0
  107. package/src/code-tool.ts +146 -0
  108. package/src/compat.ts +483 -0
  109. package/src/docs-search-tool.ts +48 -0
  110. package/src/dynamic-tools.ts +153 -0
  111. package/src/filtering.ts +14 -0
  112. package/src/headers.ts +10 -0
  113. package/src/http.ts +127 -0
  114. package/src/index.ts +108 -0
  115. package/src/options.ts +466 -0
  116. package/src/server.ts +207 -0
  117. package/src/stdio.ts +13 -0
  118. package/src/tools/index.ts +95 -0
  119. package/src/tools/logs/raw/bots-logs-raw.ts +196 -0
  120. package/src/tools/logs/raw/logs-logs-raw.ts +186 -0
  121. package/src/tools/organizations/categories/list-organizations-categories.ts +44 -0
  122. package/src/tools/organizations/categories/prompts-organizations-categories.ts +50 -0
  123. package/src/tools/organizations/categories/tags-organizations-categories.ts +50 -0
  124. package/src/tools/organizations/categories/topics-organizations-categories.ts +50 -0
  125. package/src/tools/organizations/domains-organizations.ts +44 -0
  126. package/src/tools/organizations/models-organizations.ts +44 -0
  127. package/src/tools/organizations/regions-organizations.ts +44 -0
  128. package/src/tools/prompts/answers-prompts.ts +200 -0
  129. package/src/tools/reports/citations-reports.ts +173 -0
  130. package/src/tools/reports/sentiment-reports.ts +173 -0
  131. package/src/tools/reports/visibility-reports.ts +173 -0
  132. package/src/tools/types.ts +103 -0
  133. package/src/tools.ts +1 -0
  134. package/src/tsconfig.json +11 -0
  135. package/stdio.d.mts +3 -0
  136. package/stdio.d.mts.map +1 -0
  137. package/stdio.d.ts +3 -0
  138. package/stdio.d.ts.map +1 -0
  139. package/stdio.js +14 -0
  140. package/stdio.js.map +1 -0
  141. package/stdio.mjs +10 -0
  142. package/stdio.mjs.map +1 -0
  143. package/tools/index.d.mts +10 -0
  144. package/tools/index.d.mts.map +1 -0
  145. package/tools/index.d.ts +10 -0
  146. package/tools/index.d.ts.map +1 -0
  147. package/tools/index.js +79 -0
  148. package/tools/index.js.map +1 -0
  149. package/tools/index.mjs +72 -0
  150. package/tools/index.mjs.map +1 -0
  151. package/tools/logs/raw/bots-logs-raw.d.mts +45 -0
  152. package/tools/logs/raw/bots-logs-raw.d.mts.map +1 -0
  153. package/tools/logs/raw/bots-logs-raw.d.ts +45 -0
  154. package/tools/logs/raw/bots-logs-raw.d.ts.map +1 -0
  155. package/tools/logs/raw/bots-logs-raw.js +187 -0
  156. package/tools/logs/raw/bots-logs-raw.js.map +1 -0
  157. package/tools/logs/raw/bots-logs-raw.mjs +183 -0
  158. package/tools/logs/raw/bots-logs-raw.mjs.map +1 -0
  159. package/tools/logs/raw/logs-logs-raw.d.mts +45 -0
  160. package/tools/logs/raw/logs-logs-raw.d.mts.map +1 -0
  161. package/tools/logs/raw/logs-logs-raw.d.ts +45 -0
  162. package/tools/logs/raw/logs-logs-raw.d.ts.map +1 -0
  163. package/tools/logs/raw/logs-logs-raw.js +177 -0
  164. package/tools/logs/raw/logs-logs-raw.js.map +1 -0
  165. package/tools/logs/raw/logs-logs-raw.mjs +173 -0
  166. package/tools/logs/raw/logs-logs-raw.mjs.map +1 -0
  167. package/tools/organizations/categories/list-organizations-categories.d.mts +45 -0
  168. package/tools/organizations/categories/list-organizations-categories.d.mts.map +1 -0
  169. package/tools/organizations/categories/list-organizations-categories.d.ts +45 -0
  170. package/tools/organizations/categories/list-organizations-categories.d.ts.map +1 -0
  171. package/tools/organizations/categories/list-organizations-categories.js +39 -0
  172. package/tools/organizations/categories/list-organizations-categories.js.map +1 -0
  173. package/tools/organizations/categories/list-organizations-categories.mjs +35 -0
  174. package/tools/organizations/categories/list-organizations-categories.mjs.map +1 -0
  175. package/tools/organizations/categories/prompts-organizations-categories.d.mts +45 -0
  176. package/tools/organizations/categories/prompts-organizations-categories.d.mts.map +1 -0
  177. package/tools/organizations/categories/prompts-organizations-categories.d.ts +45 -0
  178. package/tools/organizations/categories/prompts-organizations-categories.d.ts.map +1 -0
  179. package/tools/organizations/categories/prompts-organizations-categories.js +43 -0
  180. package/tools/organizations/categories/prompts-organizations-categories.js.map +1 -0
  181. package/tools/organizations/categories/prompts-organizations-categories.mjs +39 -0
  182. package/tools/organizations/categories/prompts-organizations-categories.mjs.map +1 -0
  183. package/tools/organizations/categories/tags-organizations-categories.d.mts +45 -0
  184. package/tools/organizations/categories/tags-organizations-categories.d.mts.map +1 -0
  185. package/tools/organizations/categories/tags-organizations-categories.d.ts +45 -0
  186. package/tools/organizations/categories/tags-organizations-categories.d.ts.map +1 -0
  187. package/tools/organizations/categories/tags-organizations-categories.js +43 -0
  188. package/tools/organizations/categories/tags-organizations-categories.js.map +1 -0
  189. package/tools/organizations/categories/tags-organizations-categories.mjs +39 -0
  190. package/tools/organizations/categories/tags-organizations-categories.mjs.map +1 -0
  191. package/tools/organizations/categories/topics-organizations-categories.d.mts +45 -0
  192. package/tools/organizations/categories/topics-organizations-categories.d.mts.map +1 -0
  193. package/tools/organizations/categories/topics-organizations-categories.d.ts +45 -0
  194. package/tools/organizations/categories/topics-organizations-categories.d.ts.map +1 -0
  195. package/tools/organizations/categories/topics-organizations-categories.js +43 -0
  196. package/tools/organizations/categories/topics-organizations-categories.js.map +1 -0
  197. package/tools/organizations/categories/topics-organizations-categories.mjs +39 -0
  198. package/tools/organizations/categories/topics-organizations-categories.mjs.map +1 -0
  199. package/tools/organizations/domains-organizations.d.mts +45 -0
  200. package/tools/organizations/domains-organizations.d.mts.map +1 -0
  201. package/tools/organizations/domains-organizations.d.ts +45 -0
  202. package/tools/organizations/domains-organizations.d.ts.map +1 -0
  203. package/tools/organizations/domains-organizations.js +39 -0
  204. package/tools/organizations/domains-organizations.js.map +1 -0
  205. package/tools/organizations/domains-organizations.mjs +35 -0
  206. package/tools/organizations/domains-organizations.mjs.map +1 -0
  207. package/tools/organizations/models-organizations.d.mts +45 -0
  208. package/tools/organizations/models-organizations.d.mts.map +1 -0
  209. package/tools/organizations/models-organizations.d.ts +45 -0
  210. package/tools/organizations/models-organizations.d.ts.map +1 -0
  211. package/tools/organizations/models-organizations.js +39 -0
  212. package/tools/organizations/models-organizations.js.map +1 -0
  213. package/tools/organizations/models-organizations.mjs +35 -0
  214. package/tools/organizations/models-organizations.mjs.map +1 -0
  215. package/tools/organizations/regions-organizations.d.mts +45 -0
  216. package/tools/organizations/regions-organizations.d.mts.map +1 -0
  217. package/tools/organizations/regions-organizations.d.ts +45 -0
  218. package/tools/organizations/regions-organizations.d.ts.map +1 -0
  219. package/tools/organizations/regions-organizations.js +39 -0
  220. package/tools/organizations/regions-organizations.js.map +1 -0
  221. package/tools/organizations/regions-organizations.mjs +35 -0
  222. package/tools/organizations/regions-organizations.mjs.map +1 -0
  223. package/tools/prompts/answers-prompts.d.mts +45 -0
  224. package/tools/prompts/answers-prompts.d.mts.map +1 -0
  225. package/tools/prompts/answers-prompts.d.ts +45 -0
  226. package/tools/prompts/answers-prompts.d.ts.map +1 -0
  227. package/tools/prompts/answers-prompts.js +194 -0
  228. package/tools/prompts/answers-prompts.js.map +1 -0
  229. package/tools/prompts/answers-prompts.mjs +190 -0
  230. package/tools/prompts/answers-prompts.mjs.map +1 -0
  231. package/tools/reports/citations-reports.d.mts +45 -0
  232. package/tools/reports/citations-reports.d.mts.map +1 -0
  233. package/tools/reports/citations-reports.d.ts +45 -0
  234. package/tools/reports/citations-reports.d.ts.map +1 -0
  235. package/tools/reports/citations-reports.js +164 -0
  236. package/tools/reports/citations-reports.js.map +1 -0
  237. package/tools/reports/citations-reports.mjs +160 -0
  238. package/tools/reports/citations-reports.mjs.map +1 -0
  239. package/tools/reports/sentiment-reports.d.mts +45 -0
  240. package/tools/reports/sentiment-reports.d.mts.map +1 -0
  241. package/tools/reports/sentiment-reports.d.ts +45 -0
  242. package/tools/reports/sentiment-reports.d.ts.map +1 -0
  243. package/tools/reports/sentiment-reports.js +164 -0
  244. package/tools/reports/sentiment-reports.js.map +1 -0
  245. package/tools/reports/sentiment-reports.mjs +160 -0
  246. package/tools/reports/sentiment-reports.mjs.map +1 -0
  247. package/tools/reports/visibility-reports.d.mts +45 -0
  248. package/tools/reports/visibility-reports.d.mts.map +1 -0
  249. package/tools/reports/visibility-reports.d.ts +45 -0
  250. package/tools/reports/visibility-reports.d.ts.map +1 -0
  251. package/tools/reports/visibility-reports.js +164 -0
  252. package/tools/reports/visibility-reports.js.map +1 -0
  253. package/tools/reports/visibility-reports.mjs +160 -0
  254. package/tools/reports/visibility-reports.mjs.map +1 -0
  255. package/tools/types.d.mts +51 -0
  256. package/tools/types.d.mts.map +1 -0
  257. package/tools/types.d.ts +51 -0
  258. package/tools/types.d.ts.map +1 -0
  259. package/tools/types.js +46 -0
  260. package/tools/types.js.map +1 -0
  261. package/tools/types.mjs +42 -0
  262. package/tools/types.mjs.map +1 -0
  263. package/tools.d.mts +2 -0
  264. package/tools.d.mts.map +1 -0
  265. package/tools.d.ts +2 -0
  266. package/tools.d.ts.map +1 -0
  267. package/tools.js +18 -0
  268. package/tools.js.map +1 -0
  269. package/tools.mjs +2 -0
  270. package/tools.mjs.map +1 -0
package/src/server.ts ADDED
@@ -0,0 +1,207 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
4
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
+ import { Endpoint, endpoints, HandlerFunction, query } from './tools';
6
+ import {
7
+ CallToolRequestSchema,
8
+ ListToolsRequestSchema,
9
+ SetLevelRequestSchema,
10
+ Implementation,
11
+ Tool,
12
+ } from '@modelcontextprotocol/sdk/types.js';
13
+ import { ClientOptions } from 'profoundai';
14
+ import Profound from 'profoundai';
15
+ import {
16
+ applyCompatibilityTransformations,
17
+ ClientCapabilities,
18
+ defaultClientCapabilities,
19
+ knownClients,
20
+ parseEmbeddedJSON,
21
+ } from './compat';
22
+ import { dynamicTools } from './dynamic-tools';
23
+ import { codeTool } from './code-tool';
24
+ import docsSearchTool from './docs-search-tool';
25
+ import { McpOptions } from './options';
26
+
27
+ export { McpOptions } from './options';
28
+ export { ClientType } from './compat';
29
+ export { Filter } from './tools';
30
+ export { ClientOptions } from 'profoundai';
31
+ export { endpoints } from './tools';
32
+
33
+ export const newMcpServer = () =>
34
+ new McpServer(
35
+ {
36
+ name: 'profoundai_api',
37
+ version: '0.2.1',
38
+ },
39
+ { capabilities: { tools: {}, logging: {} } },
40
+ );
41
+
42
+ // Create server instance
43
+ export const server = newMcpServer();
44
+
45
+ /**
46
+ * Initializes the provided MCP Server with the given tools and handlers.
47
+ * If not provided, the default client, tools and handlers will be used.
48
+ */
49
+ export function initMcpServer(params: {
50
+ server: Server | McpServer;
51
+ clientOptions?: ClientOptions;
52
+ mcpOptions?: McpOptions;
53
+ }) {
54
+ const server = params.server instanceof McpServer ? params.server.server : params.server;
55
+ const mcpOptions = params.mcpOptions ?? {};
56
+
57
+ let providedEndpoints: Endpoint[] | null = null;
58
+ let endpointMap: Record<string, Endpoint> | null = null;
59
+
60
+ const initTools = async (implementation?: Implementation) => {
61
+ if (implementation && (!mcpOptions.client || mcpOptions.client === 'infer')) {
62
+ mcpOptions.client =
63
+ implementation.name.toLowerCase().includes('claude') ? 'claude'
64
+ : implementation.name.toLowerCase().includes('cursor') ? 'cursor'
65
+ : undefined;
66
+ mcpOptions.capabilities = {
67
+ ...(mcpOptions.client && knownClients[mcpOptions.client]),
68
+ ...mcpOptions.capabilities,
69
+ };
70
+ }
71
+ providedEndpoints ??= await selectTools(endpoints, mcpOptions);
72
+ endpointMap ??= Object.fromEntries(providedEndpoints.map((endpoint) => [endpoint.tool.name, endpoint]));
73
+ };
74
+
75
+ const logAtLevel =
76
+ (level: 'debug' | 'info' | 'warning' | 'error') =>
77
+ (message: string, ...rest: unknown[]) => {
78
+ void server.sendLoggingMessage({
79
+ level,
80
+ data: { message, rest },
81
+ });
82
+ };
83
+ const logger = {
84
+ debug: logAtLevel('debug'),
85
+ info: logAtLevel('info'),
86
+ warn: logAtLevel('warning'),
87
+ error: logAtLevel('error'),
88
+ };
89
+
90
+ let client = new Profound({
91
+ logger,
92
+ ...params.clientOptions,
93
+ defaultHeaders: {
94
+ ...params.clientOptions?.defaultHeaders,
95
+ 'X-Stainless-MCP': 'true',
96
+ },
97
+ });
98
+
99
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
100
+ if (providedEndpoints === null) {
101
+ await initTools(server.getClientVersion());
102
+ }
103
+ return {
104
+ tools: providedEndpoints!.map((endpoint) => endpoint.tool),
105
+ };
106
+ });
107
+
108
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
109
+ if (endpointMap === null) {
110
+ await initTools(server.getClientVersion());
111
+ }
112
+ const { name, arguments: args } = request.params;
113
+ const endpoint = endpointMap![name];
114
+ if (!endpoint) {
115
+ throw new Error(`Unknown tool: ${name}`);
116
+ }
117
+
118
+ return executeHandler(endpoint.tool, endpoint.handler, client, args, mcpOptions.capabilities);
119
+ });
120
+
121
+ server.setRequestHandler(SetLevelRequestSchema, async (request) => {
122
+ const { level } = request.params;
123
+ switch (level) {
124
+ case 'debug':
125
+ client = client.withOptions({ logLevel: 'debug' });
126
+ break;
127
+ case 'info':
128
+ client = client.withOptions({ logLevel: 'info' });
129
+ break;
130
+ case 'notice':
131
+ case 'warning':
132
+ client = client.withOptions({ logLevel: 'warn' });
133
+ break;
134
+ case 'error':
135
+ client = client.withOptions({ logLevel: 'error' });
136
+ break;
137
+ default:
138
+ client = client.withOptions({ logLevel: 'off' });
139
+ break;
140
+ }
141
+ return {};
142
+ });
143
+ }
144
+
145
+ /**
146
+ * Selects the tools to include in the MCP Server based on the provided options.
147
+ */
148
+ export async function selectTools(endpoints: Endpoint[], options?: McpOptions): Promise<Endpoint[]> {
149
+ const filteredEndpoints = query(options?.filters ?? [], endpoints);
150
+
151
+ let includedTools = filteredEndpoints.slice();
152
+
153
+ if (includedTools.length > 0) {
154
+ if (options?.includeDynamicTools) {
155
+ includedTools = dynamicTools(includedTools);
156
+ }
157
+ } else {
158
+ if (options?.includeAllTools) {
159
+ includedTools = endpoints.slice();
160
+ } else if (options?.includeDynamicTools) {
161
+ includedTools = dynamicTools(endpoints);
162
+ } else if (options?.includeCodeTools) {
163
+ includedTools = [await codeTool()];
164
+ } else {
165
+ includedTools = endpoints.slice();
166
+ }
167
+ }
168
+ if (options?.includeDocsTools ?? true) {
169
+ includedTools.push(docsSearchTool);
170
+ }
171
+ const capabilities = { ...defaultClientCapabilities, ...options?.capabilities };
172
+ return applyCompatibilityTransformations(includedTools, capabilities);
173
+ }
174
+
175
+ /**
176
+ * Runs the provided handler with the given client and arguments.
177
+ */
178
+ export async function executeHandler(
179
+ tool: Tool,
180
+ handler: HandlerFunction,
181
+ client: Profound,
182
+ args: Record<string, unknown> | undefined,
183
+ compatibilityOptions?: Partial<ClientCapabilities>,
184
+ ) {
185
+ const options = { ...defaultClientCapabilities, ...compatibilityOptions };
186
+ if (!options.validJson && args) {
187
+ args = parseEmbeddedJSON(args, tool.inputSchema);
188
+ }
189
+ return await handler(client, args || {});
190
+ }
191
+
192
+ export const readEnv = (env: string): string | undefined => {
193
+ if (typeof (globalThis as any).process !== 'undefined') {
194
+ return (globalThis as any).process.env?.[env]?.trim();
195
+ } else if (typeof (globalThis as any).Deno !== 'undefined') {
196
+ return (globalThis as any).Deno.env?.get?.(env)?.trim();
197
+ }
198
+ return;
199
+ };
200
+
201
+ export const readEnvOrError = (env: string): string => {
202
+ let envValue = readEnv(env);
203
+ if (envValue === undefined) {
204
+ throw new Error(`Environment variable ${env} is not set`);
205
+ }
206
+ return envValue;
207
+ };
package/src/stdio.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
2
+ import { initMcpServer, newMcpServer } from './server';
3
+ import { McpOptions } from './options';
4
+
5
+ export const launchStdioServer = async (options: McpOptions) => {
6
+ const server = newMcpServer();
7
+
8
+ initMcpServer({ server, mcpOptions: options });
9
+
10
+ const transport = new StdioServerTransport();
11
+ await server.connect(transport);
12
+ console.error('MCP Server running on stdio');
13
+ };
@@ -0,0 +1,95 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { Metadata, Endpoint, HandlerFunction } from './types';
4
+
5
+ export { Metadata, Endpoint, HandlerFunction };
6
+
7
+ import domains_organizations from './organizations/domains-organizations';
8
+ import models_organizations from './organizations/models-organizations';
9
+ import regions_organizations from './organizations/regions-organizations';
10
+ import list_organizations_categories from './organizations/categories/list-organizations-categories';
11
+ import prompts_organizations_categories from './organizations/categories/prompts-organizations-categories';
12
+ import tags_organizations_categories from './organizations/categories/tags-organizations-categories';
13
+ import topics_organizations_categories from './organizations/categories/topics-organizations-categories';
14
+ import answers_prompts from './prompts/answers-prompts';
15
+ import citations_reports from './reports/citations-reports';
16
+ import sentiment_reports from './reports/sentiment-reports';
17
+ import visibility_reports from './reports/visibility-reports';
18
+ import bots_logs_raw from './logs/raw/bots-logs-raw';
19
+ import logs_logs_raw from './logs/raw/logs-logs-raw';
20
+
21
+ export const endpoints: Endpoint[] = [];
22
+
23
+ function addEndpoint(endpoint: Endpoint) {
24
+ endpoints.push(endpoint);
25
+ }
26
+
27
+ addEndpoint(domains_organizations);
28
+ addEndpoint(models_organizations);
29
+ addEndpoint(regions_organizations);
30
+ addEndpoint(list_organizations_categories);
31
+ addEndpoint(prompts_organizations_categories);
32
+ addEndpoint(tags_organizations_categories);
33
+ addEndpoint(topics_organizations_categories);
34
+ addEndpoint(answers_prompts);
35
+ addEndpoint(citations_reports);
36
+ addEndpoint(sentiment_reports);
37
+ addEndpoint(visibility_reports);
38
+ addEndpoint(bots_logs_raw);
39
+ addEndpoint(logs_logs_raw);
40
+
41
+ export type Filter = {
42
+ type: 'resource' | 'operation' | 'tag' | 'tool';
43
+ op: 'include' | 'exclude';
44
+ value: string;
45
+ };
46
+
47
+ export function query(filters: Filter[], endpoints: Endpoint[]): Endpoint[] {
48
+ const allExcludes = filters.length > 0 && filters.every((filter) => filter.op === 'exclude');
49
+ const unmatchedFilters = new Set(filters);
50
+
51
+ const filtered = endpoints.filter((endpoint: Endpoint) => {
52
+ let included = false || allExcludes;
53
+
54
+ for (const filter of filters) {
55
+ if (match(filter, endpoint)) {
56
+ unmatchedFilters.delete(filter);
57
+ included = filter.op === 'include';
58
+ }
59
+ }
60
+
61
+ return included;
62
+ });
63
+
64
+ // Check if any filters didn't match
65
+ const unmatched = Array.from(unmatchedFilters).filter((f) => f.type === 'tool' || f.type === 'resource');
66
+ if (unmatched.length > 0) {
67
+ throw new Error(
68
+ `The following filters did not match any endpoints: ${unmatched
69
+ .map((f) => `${f.type}=${f.value}`)
70
+ .join(', ')}`,
71
+ );
72
+ }
73
+
74
+ return filtered;
75
+ }
76
+
77
+ function match({ type, value }: Filter, endpoint: Endpoint): boolean {
78
+ switch (type) {
79
+ case 'resource': {
80
+ const regexStr = '^' + normalizeResource(value).replace(/\*/g, '.*') + '$';
81
+ const regex = new RegExp(regexStr);
82
+ return regex.test(normalizeResource(endpoint.metadata.resource));
83
+ }
84
+ case 'operation':
85
+ return endpoint.metadata.operation === value;
86
+ case 'tag':
87
+ return endpoint.metadata.tags.includes(value);
88
+ case 'tool':
89
+ return endpoint.tool.name === value;
90
+ }
91
+ }
92
+
93
+ function normalizeResource(resource: string): string {
94
+ return resource.toLowerCase().replace(/[^a-z.*\-_]*/g, '');
95
+ }
@@ -0,0 +1,196 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { maybeFilter } from 'profound-mcp/filtering';
4
+ import { Metadata, asTextContentResult } from 'profound-mcp/tools/types';
5
+
6
+ import { Tool } from '@modelcontextprotocol/sdk/types.js';
7
+ import Profound from 'profoundai';
8
+
9
+ export const metadata: Metadata = {
10
+ resource: 'logs.raw',
11
+ operation: 'write',
12
+ tags: [],
13
+ httpMethod: 'post',
14
+ httpPath: '/v1/logs/raw/bots',
15
+ operationId: 'get_bots_v1_logs_raw_bots_post',
16
+ };
17
+
18
+ export const tool: Tool = {
19
+ name: 'bots_logs_raw',
20
+ description:
21
+ "When using this tool, always use the `jq_filter` parameter to reduce the response size and improve performance.\n\nOnly omit if you're sure you don't need the data.\n\nGet identified bot logs with filters\n\n# Response Schema\n```json\n{\n $ref: '#/$defs/raw_bots_response',\n $defs: {\n raw_bots_response: {\n anyOf: [ {\n type: 'array',\n title: 'LogVisitBotList',\n items: {\n type: 'object',\n title: 'LogVisitBot',\n description: 'DB Model for a bot visit.',\n properties: {\n bot_name: {\n type: 'string',\n title: 'Bot Name'\n },\n bot_provider: {\n type: 'string',\n title: 'Bot Provider'\n },\n bot_types: {\n type: 'array',\n title: 'Bot Types',\n items: {\n type: 'string',\n enum: [ 'ai_assistant',\n 'ai_training',\n 'index'\n ]\n }\n },\n host: {\n type: 'string',\n title: 'Host'\n },\n ip: {\n type: 'string',\n title: 'Ip'\n },\n method: {\n type: 'string',\n title: 'Method'\n },\n org_id: {\n type: 'string',\n title: 'Org Id'\n },\n path: {\n type: 'string',\n title: 'Path'\n },\n status_code: {\n type: 'integer',\n title: 'Status Code'\n },\n timestamp: {\n type: 'string',\n title: 'Timestamp',\n format: 'date-time'\n },\n user_agent: {\n type: 'string',\n title: 'User Agent'\n },\n bytes_sent: {\n type: 'integer',\n title: 'Bytes Sent'\n },\n duration_ms: {\n type: 'integer',\n title: 'Duration Ms'\n },\n query_params: {\n type: 'object',\n title: 'Query Params',\n additionalProperties: true\n },\n referer: {\n type: 'string',\n title: 'Referer'\n }\n },\n required: [ 'bot_name',\n 'bot_provider',\n 'bot_types',\n 'host',\n 'ip',\n 'method',\n 'org_id',\n 'path',\n 'status_code',\n 'timestamp',\n 'user_agent'\n ]\n }\n },\n {\n $ref: '#/$defs/report_response'\n }\n ],\n title: 'Response Get Bots V1 Logs Raw Bots Post',\n description: 'Base response model for reports.'\n },\n report_response: {\n type: 'object',\n title: 'Response',\n description: 'Base response model for reports.',\n properties: {\n data: {\n type: 'array',\n title: 'Data',\n items: {\n $ref: '#/$defs/report_result'\n }\n },\n info: {\n $ref: '#/$defs/report_info'\n }\n },\n required: [ 'data',\n 'info'\n ]\n },\n report_result: {\n type: 'object',\n title: 'Result',\n description: 'Base model for report results.',\n properties: {\n dimensions: {\n type: 'array',\n title: 'Dimensions',\n items: {\n type: 'string'\n }\n },\n metrics: {\n type: 'array',\n title: 'Metrics',\n items: {\n type: 'number'\n }\n }\n },\n required: [ 'dimensions',\n 'metrics'\n ]\n },\n report_info: {\n type: 'object',\n title: 'Info',\n description: 'Base model for report information.',\n properties: {\n total_rows: {\n type: 'integer',\n title: 'Total Rows'\n },\n query: {\n type: 'object',\n title: 'Query',\n additionalProperties: true\n }\n },\n required: [ 'total_rows'\n ]\n }\n }\n}\n```",
22
+ inputSchema: {
23
+ type: 'object',
24
+ properties: {
25
+ domain: {
26
+ type: 'string',
27
+ title: 'Domain',
28
+ description: 'Domain to query logs for.',
29
+ },
30
+ metrics: {
31
+ type: 'array',
32
+ title: 'Metrics',
33
+ items: {
34
+ type: 'string',
35
+ enum: ['count'],
36
+ },
37
+ },
38
+ start_date: {
39
+ type: 'string',
40
+ title: 'Start Date',
41
+ description:
42
+ 'Start date for logs. Accepts: YYYY-MM-DD, YYYY-MM-DD HH:MM, YYYY-MM-DD HH:MM:SS, or full ISO timestamp.',
43
+ format: 'date-time',
44
+ },
45
+ date_interval: {
46
+ type: 'string',
47
+ title: 'Date Interval',
48
+ description: 'Date interval for the report. (only used with date dimension)',
49
+ enum: ['day', 'week', 'month', 'year'],
50
+ },
51
+ dimensions: {
52
+ type: 'array',
53
+ title: 'Dimensions',
54
+ description: 'Dimensions to group the report by.',
55
+ items: {
56
+ type: 'string',
57
+ enum: [
58
+ 'method',
59
+ 'path',
60
+ 'status_code',
61
+ 'ip',
62
+ 'user_agent',
63
+ 'referer',
64
+ 'query_params',
65
+ 'bot_name',
66
+ 'bot_provider',
67
+ 'bot_types',
68
+ ],
69
+ },
70
+ },
71
+ end_date: {
72
+ type: 'string',
73
+ title: 'End Date',
74
+ description: 'End date for logs. Accepts same formats as start_date. Defaults to now if omitted.',
75
+ format: 'date-time',
76
+ },
77
+ filters: {
78
+ type: 'array',
79
+ title: 'Filters',
80
+ description: 'List of filters to apply to the report. Each filter has an operator, field, and value.',
81
+ items: {
82
+ type: 'object',
83
+ title:
84
+ "Filter[Literal['method', 'path', 'status_code', 'ip', 'user_agent', 'referer', 'query_params', 'bot_name', 'bot_provider', 'bot_types']]",
85
+ properties: {
86
+ field: {
87
+ type: 'string',
88
+ title: 'Field',
89
+ enum: [
90
+ 'method',
91
+ 'path',
92
+ 'status_code',
93
+ 'ip',
94
+ 'user_agent',
95
+ 'referer',
96
+ 'query_params',
97
+ 'bot_name',
98
+ 'bot_provider',
99
+ 'bot_types',
100
+ ],
101
+ },
102
+ operator: {
103
+ type: 'string',
104
+ title: 'Operator',
105
+ enum: [
106
+ 'is',
107
+ 'not_is',
108
+ 'in',
109
+ 'not_in',
110
+ 'contains',
111
+ 'not_contains',
112
+ 'contains_case_insensitive',
113
+ 'not_contains_case_insensitive',
114
+ 'matches',
115
+ ],
116
+ },
117
+ value: {
118
+ anyOf: [
119
+ {
120
+ type: 'string',
121
+ title: 'FilterStringValue',
122
+ },
123
+ {
124
+ type: 'array',
125
+ title: 'FilterStringListValue',
126
+ items: {
127
+ type: 'string',
128
+ },
129
+ },
130
+ {
131
+ type: 'integer',
132
+ title: 'FilterIntegerValue',
133
+ },
134
+ {
135
+ type: 'array',
136
+ title: 'FilterIntegerListValue',
137
+ items: {
138
+ type: 'integer',
139
+ },
140
+ },
141
+ ],
142
+ title: 'Value',
143
+ description:
144
+ 'Value for the filter. Can be a single value or a list of depending on the operator.',
145
+ },
146
+ },
147
+ required: ['field', 'operator', 'value'],
148
+ },
149
+ },
150
+ order_by: {
151
+ type: 'object',
152
+ title: 'Order By',
153
+ description:
154
+ "\nCustom ordering of the report results.\n\nThe order is a record of key-value pairs where:\n- key is the field to order by, which can be a metric or dimension\n- value is the direction of the order, either 'asc' for ascending or 'desc' for descending.\n\nWhen not specified, the default order is the first metric in the query descending.\n ",
155
+ additionalProperties: true,
156
+ },
157
+ pagination: {
158
+ $ref: '#/$defs/pagination',
159
+ },
160
+ jq_filter: {
161
+ type: 'string',
162
+ title: 'jq Filter',
163
+ description:
164
+ 'A jq filter to apply to the response to include certain fields. Consult the output schema in the tool description to see the fields that are available.\n\nFor example: to include only the `name` field in every object of a results array, you can provide ".results[].name".\n\nFor more information, see the [jq documentation](https://jqlang.org/manual/).',
165
+ },
166
+ },
167
+ required: ['domain', 'metrics', 'start_date'],
168
+ $defs: {
169
+ pagination: {
170
+ type: 'object',
171
+ title: 'Pagination',
172
+ description: 'Report pagination model.',
173
+ properties: {
174
+ limit: {
175
+ type: 'integer',
176
+ title: 'Limit',
177
+ description: 'Maximum number of results to return. Default is 10,000, maximum is 50,000.',
178
+ },
179
+ offset: {
180
+ type: 'integer',
181
+ title: 'Offset',
182
+ description: 'Offset for the results. Used for pagination.',
183
+ },
184
+ },
185
+ },
186
+ },
187
+ },
188
+ annotations: {},
189
+ };
190
+
191
+ export const handler = async (client: Profound, args: Record<string, unknown> | undefined) => {
192
+ const { jq_filter, ...body } = args as any;
193
+ return asTextContentResult(await maybeFilter(jq_filter, await client.logs.raw.bots(body)));
194
+ };
195
+
196
+ export default { metadata, tool, handler };