opc-agent 2.0.2 → 3.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.
Files changed (151) hide show
  1. package/README.md +603 -545
  2. package/dist/channels/voice.d.ts +59 -0
  3. package/dist/channels/voice.js +351 -1
  4. package/dist/cli.js +284 -5
  5. package/dist/core/agent.d.ts +9 -0
  6. package/dist/core/agent.js +49 -0
  7. package/dist/core/collaboration.d.ts +89 -0
  8. package/dist/core/collaboration.js +201 -0
  9. package/dist/deploy/index.d.ts +40 -0
  10. package/dist/deploy/index.js +261 -0
  11. package/dist/index.d.ts +7 -1
  12. package/dist/index.js +47 -3
  13. package/dist/mcp/servers/calculator-mcp.d.ts +3 -0
  14. package/dist/mcp/servers/calculator-mcp.js +65 -0
  15. package/dist/mcp/servers/crypto-mcp.d.ts +3 -0
  16. package/dist/mcp/servers/crypto-mcp.js +108 -0
  17. package/dist/mcp/servers/database-mcp.d.ts +3 -0
  18. package/dist/mcp/servers/database-mcp.js +73 -0
  19. package/dist/mcp/servers/datetime-mcp.d.ts +3 -0
  20. package/dist/mcp/servers/datetime-mcp.js +71 -0
  21. package/dist/mcp/servers/filesystem.d.ts +3 -0
  22. package/dist/mcp/servers/filesystem.js +101 -0
  23. package/dist/mcp/servers/github-mcp.d.ts +3 -0
  24. package/dist/mcp/servers/github-mcp.js +60 -0
  25. package/dist/mcp/servers/index.d.ts +21 -0
  26. package/dist/mcp/servers/index.js +50 -0
  27. package/dist/mcp/servers/json-mcp.d.ts +3 -0
  28. package/dist/mcp/servers/json-mcp.js +126 -0
  29. package/dist/mcp/servers/memory-mcp.d.ts +3 -0
  30. package/dist/mcp/servers/memory-mcp.js +60 -0
  31. package/dist/mcp/servers/regex-mcp.d.ts +3 -0
  32. package/dist/mcp/servers/regex-mcp.js +56 -0
  33. package/dist/mcp/servers/web-mcp.d.ts +3 -0
  34. package/dist/mcp/servers/web-mcp.js +51 -0
  35. package/dist/memory/index.d.ts +2 -0
  36. package/dist/memory/index.js +4 -1
  37. package/dist/memory/seed-loader.d.ts +51 -0
  38. package/dist/memory/seed-loader.js +200 -0
  39. package/dist/schema/oad.d.ts +292 -12
  40. package/dist/schema/oad.js +12 -1
  41. package/dist/security/guardrails.d.ts +50 -0
  42. package/dist/security/guardrails.js +197 -0
  43. package/dist/studio/server.d.ts +31 -1
  44. package/dist/studio/server.js +154 -3
  45. package/dist/studio-ui/index.html +1278 -662
  46. package/dist/tools/integrations/calendar.d.ts +3 -0
  47. package/dist/tools/integrations/calendar.js +73 -0
  48. package/dist/tools/integrations/code-exec.d.ts +3 -0
  49. package/dist/tools/integrations/code-exec.js +42 -0
  50. package/dist/tools/integrations/csv-analyzer.d.ts +3 -0
  51. package/dist/tools/integrations/csv-analyzer.js +142 -0
  52. package/dist/tools/integrations/database.d.ts +3 -0
  53. package/dist/tools/integrations/database.js +44 -0
  54. package/dist/tools/integrations/email-send.d.ts +3 -0
  55. package/dist/tools/integrations/email-send.js +104 -0
  56. package/dist/tools/integrations/git-tool.d.ts +3 -0
  57. package/dist/tools/integrations/git-tool.js +49 -0
  58. package/dist/tools/integrations/github-tool.d.ts +3 -0
  59. package/dist/tools/integrations/github-tool.js +77 -0
  60. package/dist/tools/integrations/image-gen.d.ts +3 -0
  61. package/dist/tools/integrations/image-gen.js +58 -0
  62. package/dist/tools/integrations/index.d.ts +30 -0
  63. package/dist/tools/integrations/index.js +107 -0
  64. package/dist/tools/integrations/jira.d.ts +3 -0
  65. package/dist/tools/integrations/jira.js +85 -0
  66. package/dist/tools/integrations/notion.d.ts +3 -0
  67. package/dist/tools/integrations/notion.js +71 -0
  68. package/dist/tools/integrations/npm-tool.d.ts +3 -0
  69. package/dist/tools/integrations/npm-tool.js +49 -0
  70. package/dist/tools/integrations/pdf-reader.d.ts +3 -0
  71. package/dist/tools/integrations/pdf-reader.js +91 -0
  72. package/dist/tools/integrations/slack.d.ts +3 -0
  73. package/dist/tools/integrations/slack.js +67 -0
  74. package/dist/tools/integrations/summarizer.d.ts +3 -0
  75. package/dist/tools/integrations/summarizer.js +49 -0
  76. package/dist/tools/integrations/translator.d.ts +3 -0
  77. package/dist/tools/integrations/translator.js +48 -0
  78. package/dist/tools/integrations/trello.d.ts +3 -0
  79. package/dist/tools/integrations/trello.js +60 -0
  80. package/dist/tools/integrations/vector-search.d.ts +3 -0
  81. package/dist/tools/integrations/vector-search.js +44 -0
  82. package/dist/tools/integrations/web-scraper.d.ts +3 -0
  83. package/dist/tools/integrations/web-scraper.js +48 -0
  84. package/dist/tools/integrations/web-search.d.ts +3 -0
  85. package/dist/tools/integrations/web-search.js +60 -0
  86. package/dist/tools/integrations/webhook.d.ts +3 -0
  87. package/dist/tools/integrations/webhook.js +39 -0
  88. package/dist/ui/components.d.ts +10 -0
  89. package/dist/ui/components.js +123 -0
  90. package/package.json +1 -1
  91. package/src/channels/voice.ts +365 -0
  92. package/src/cli.ts +294 -6
  93. package/src/core/agent.ts +56 -0
  94. package/src/core/collaboration.ts +275 -0
  95. package/src/deploy/index.ts +255 -0
  96. package/src/index.ts +21 -1
  97. package/src/mcp/servers/calculator-mcp.ts +65 -0
  98. package/src/mcp/servers/crypto-mcp.ts +73 -0
  99. package/src/mcp/servers/database-mcp.ts +72 -0
  100. package/src/mcp/servers/datetime-mcp.ts +69 -0
  101. package/src/mcp/servers/filesystem.ts +66 -0
  102. package/src/mcp/servers/github-mcp.ts +58 -0
  103. package/src/mcp/servers/index.ts +63 -0
  104. package/src/mcp/servers/json-mcp.ts +102 -0
  105. package/src/mcp/servers/memory-mcp.ts +56 -0
  106. package/src/mcp/servers/regex-mcp.ts +53 -0
  107. package/src/mcp/servers/web-mcp.ts +49 -0
  108. package/src/memory/index.ts +3 -0
  109. package/src/memory/seed-loader.ts +212 -0
  110. package/src/schema/oad.ts +13 -0
  111. package/src/security/guardrails.ts +248 -0
  112. package/src/studio/server.ts +166 -4
  113. package/src/studio-ui/index.html +1278 -662
  114. package/src/tools/integrations/calendar.ts +73 -0
  115. package/src/tools/integrations/code-exec.ts +39 -0
  116. package/src/tools/integrations/csv-analyzer.ts +92 -0
  117. package/src/tools/integrations/database.ts +44 -0
  118. package/src/tools/integrations/email-send.ts +76 -0
  119. package/src/tools/integrations/git-tool.ts +42 -0
  120. package/src/tools/integrations/github-tool.ts +76 -0
  121. package/src/tools/integrations/image-gen.ts +56 -0
  122. package/src/tools/integrations/index.ts +92 -0
  123. package/src/tools/integrations/jira.ts +83 -0
  124. package/src/tools/integrations/notion.ts +71 -0
  125. package/src/tools/integrations/npm-tool.ts +48 -0
  126. package/src/tools/integrations/pdf-reader.ts +58 -0
  127. package/src/tools/integrations/slack.ts +65 -0
  128. package/src/tools/integrations/summarizer.ts +49 -0
  129. package/src/tools/integrations/translator.ts +48 -0
  130. package/src/tools/integrations/trello.ts +60 -0
  131. package/src/tools/integrations/vector-search.ts +42 -0
  132. package/src/tools/integrations/web-scraper.ts +47 -0
  133. package/src/tools/integrations/web-search.ts +58 -0
  134. package/src/tools/integrations/webhook.ts +38 -0
  135. package/src/ui/components.ts +127 -0
  136. package/tests/brain-seed-extended.test.ts +490 -0
  137. package/tests/brain-seed.test.ts +239 -0
  138. package/tests/collaboration.test.ts +319 -0
  139. package/tests/deploy-and-dag.test.ts +196 -0
  140. package/tests/guardrails.test.ts +177 -0
  141. package/tests/integrations.test.ts +249 -0
  142. package/tests/mcp-servers.test.ts +260 -0
  143. package/tests/voice-enhanced.test.ts +169 -0
  144. package/dist/dtv/data.d.ts +0 -18
  145. package/dist/dtv/data.js +0 -25
  146. package/dist/dtv/trust.d.ts +0 -19
  147. package/dist/dtv/trust.js +0 -40
  148. package/dist/dtv/value.d.ts +0 -23
  149. package/dist/dtv/value.js +0 -38
  150. package/dist/marketplace/index.d.ts +0 -34
  151. package/dist/marketplace/index.js +0 -202
@@ -0,0 +1,83 @@
1
+ import type { MCPTool, MCPToolResult } from '../mcp';
2
+
3
+ export const JiraTool: MCPTool = {
4
+ name: 'jira',
5
+ description: 'Interact with Jira: create issues, update status, search, add comments. Requires JIRA_URL, JIRA_EMAIL, JIRA_API_TOKEN env vars.',
6
+ inputSchema: {
7
+ type: 'object',
8
+ properties: {
9
+ action: { type: 'string', enum: ['create_issue', 'update_status', 'search', 'add_comment'], description: 'Action to perform' },
10
+ project: { type: 'string', description: 'Project key (for create_issue)' },
11
+ summary: { type: 'string', description: 'Issue summary' },
12
+ description: { type: 'string', description: 'Issue description' },
13
+ issue_type: { type: 'string', description: 'Issue type (default: Task)' },
14
+ issue_key: { type: 'string', description: 'Issue key (e.g., PROJ-123)' },
15
+ status: { type: 'string', description: 'Target status (for update_status)' },
16
+ comment: { type: 'string', description: 'Comment text' },
17
+ jql: { type: 'string', description: 'JQL query (for search)' },
18
+ },
19
+ required: ['action'],
20
+ },
21
+
22
+ async execute(input: Record<string, unknown>): Promise<MCPToolResult> {
23
+ const baseUrl = process.env.JIRA_URL;
24
+ const email = process.env.JIRA_EMAIL;
25
+ const apiToken = process.env.JIRA_API_TOKEN;
26
+ if (!baseUrl || !email || !apiToken) return { content: 'Error: JIRA_URL, JIRA_EMAIL, JIRA_API_TOKEN required', isError: true };
27
+
28
+ const auth = Buffer.from(`${email}:${apiToken}`).toString('base64');
29
+ const headers = { 'Authorization': `Basic ${auth}`, 'Content-Type': 'application/json', 'Accept': 'application/json' };
30
+ const action = String(input.action ?? '');
31
+
32
+ try {
33
+ if (action === 'create_issue') {
34
+ if (!input.project || !input.summary) return { content: 'Error: project, summary required', isError: true };
35
+ const res = await fetch(`${baseUrl}/rest/api/3/issue`, {
36
+ method: 'POST', headers,
37
+ body: JSON.stringify({
38
+ fields: {
39
+ project: { key: input.project },
40
+ summary: input.summary,
41
+ description: input.description ? { type: 'doc', version: 1, content: [{ type: 'paragraph', content: [{ type: 'text', text: String(input.description) }] }] } : undefined,
42
+ issuetype: { name: String(input.issue_type ?? 'Task') },
43
+ },
44
+ }),
45
+ });
46
+ const data = await res.json() as Record<string, unknown>;
47
+ return { content: `Issue created: ${data.key}` };
48
+ }
49
+
50
+ if (action === 'update_status') {
51
+ if (!input.issue_key || !input.status) return { content: 'Error: issue_key, status required', isError: true };
52
+ const trRes = await fetch(`${baseUrl}/rest/api/3/issue/${input.issue_key}/transitions`, { headers });
53
+ const trData = await trRes.json() as { transitions: Array<{ id: string; name: string }> };
54
+ const transition = trData.transitions?.find((t) => t.name.toLowerCase() === String(input.status).toLowerCase());
55
+ if (!transition) return { content: `No transition found for status: ${input.status}`, isError: true };
56
+ await fetch(`${baseUrl}/rest/api/3/issue/${input.issue_key}/transitions`, {
57
+ method: 'POST', headers, body: JSON.stringify({ transition: { id: transition.id } }),
58
+ });
59
+ return { content: `${input.issue_key} moved to ${input.status}` };
60
+ }
61
+
62
+ if (action === 'search') {
63
+ if (!input.jql) return { content: 'Error: jql required', isError: true };
64
+ const res = await fetch(`${baseUrl}/rest/api/3/search?jql=${encodeURIComponent(String(input.jql))}&maxResults=20`, { headers });
65
+ const data = await res.json() as Record<string, unknown>;
66
+ return { content: JSON.stringify(data, null, 2).slice(0, 4000) };
67
+ }
68
+
69
+ if (action === 'add_comment') {
70
+ if (!input.issue_key || !input.comment) return { content: 'Error: issue_key, comment required', isError: true };
71
+ await fetch(`${baseUrl}/rest/api/3/issue/${input.issue_key}/comment`, {
72
+ method: 'POST', headers,
73
+ body: JSON.stringify({ body: { type: 'doc', version: 1, content: [{ type: 'paragraph', content: [{ type: 'text', text: String(input.comment) }] }] } }),
74
+ });
75
+ return { content: `Comment added to ${input.issue_key}` };
76
+ }
77
+
78
+ return { content: `Unknown action: ${action}`, isError: true };
79
+ } catch (err) {
80
+ return { content: `Jira error: ${(err as Error).message}`, isError: true };
81
+ }
82
+ },
83
+ };
@@ -0,0 +1,71 @@
1
+ import type { MCPTool, MCPToolResult } from '../mcp';
2
+
3
+ export const NotionTool: MCPTool = {
4
+ name: 'notion',
5
+ description: 'Interact with Notion API: create pages, search, append blocks. Requires NOTION_API_KEY env var.',
6
+ inputSchema: {
7
+ type: 'object',
8
+ properties: {
9
+ action: { type: 'string', enum: ['create_page', 'search', 'append_block'], description: 'Action to perform' },
10
+ parent_id: { type: 'string', description: 'Parent page/database ID' },
11
+ title: { type: 'string', description: 'Page title (for create_page)' },
12
+ content: { type: 'string', description: 'Content text (for create_page or append_block)' },
13
+ query: { type: 'string', description: 'Search query (for search)' },
14
+ block_id: { type: 'string', description: 'Block ID (for append_block)' },
15
+ },
16
+ required: ['action'],
17
+ },
18
+
19
+ async execute(input: Record<string, unknown>): Promise<MCPToolResult> {
20
+ const apiKey = process.env.NOTION_API_KEY;
21
+ if (!apiKey) return { content: 'Error: NOTION_API_KEY required', isError: true };
22
+
23
+ const action = String(input.action ?? '');
24
+ const headers = {
25
+ 'Authorization': `Bearer ${apiKey}`,
26
+ 'Content-Type': 'application/json',
27
+ 'Notion-Version': '2022-06-28',
28
+ };
29
+
30
+ try {
31
+ if (action === 'create_page') {
32
+ if (!input.parent_id) return { content: 'Error: parent_id required', isError: true };
33
+ const res = await fetch('https://api.notion.com/v1/pages', {
34
+ method: 'POST', headers,
35
+ body: JSON.stringify({
36
+ parent: { page_id: input.parent_id },
37
+ properties: { title: { title: [{ text: { content: String(input.title ?? 'Untitled') } }] } },
38
+ children: input.content ? [{ object: 'block', type: 'paragraph', paragraph: { rich_text: [{ text: { content: String(input.content) } }] } }] : [],
39
+ }),
40
+ });
41
+ const data = await res.json() as Record<string, unknown>;
42
+ return { content: `Page created: ${data.id ?? 'unknown'}` };
43
+ }
44
+
45
+ if (action === 'search') {
46
+ const res = await fetch('https://api.notion.com/v1/search', {
47
+ method: 'POST', headers,
48
+ body: JSON.stringify({ query: String(input.query ?? '') }),
49
+ });
50
+ const data = await res.json() as Record<string, unknown>;
51
+ return { content: JSON.stringify(data, null, 2).slice(0, 4000) };
52
+ }
53
+
54
+ if (action === 'append_block') {
55
+ if (!input.block_id) return { content: 'Error: block_id required', isError: true };
56
+ const res = await fetch(`https://api.notion.com/v1/blocks/${input.block_id}/children`, {
57
+ method: 'PATCH', headers,
58
+ body: JSON.stringify({
59
+ children: [{ object: 'block', type: 'paragraph', paragraph: { rich_text: [{ text: { content: String(input.content ?? '') } }] } }],
60
+ }),
61
+ });
62
+ const data = await res.json() as Record<string, unknown>;
63
+ return { content: `Block appended: ${JSON.stringify(data).slice(0, 500)}` };
64
+ }
65
+
66
+ return { content: `Unknown action: ${action}`, isError: true };
67
+ } catch (err) {
68
+ return { content: `Notion error: ${(err as Error).message}`, isError: true };
69
+ }
70
+ },
71
+ };
@@ -0,0 +1,48 @@
1
+ import type { MCPTool, MCPToolResult } from '../mcp';
2
+
3
+ export const NpmTool: MCPTool = {
4
+ name: 'npm',
5
+ description: 'Search npm registry, get package info, or list installed packages.',
6
+ inputSchema: {
7
+ type: 'object',
8
+ properties: {
9
+ action: { type: 'string', enum: ['search', 'info', 'install'], description: 'Action' },
10
+ package: { type: 'string', description: 'Package name' },
11
+ query: { type: 'string', description: 'Search query (for search)' },
12
+ },
13
+ required: ['action'],
14
+ },
15
+
16
+ async execute(input: Record<string, unknown>): Promise<MCPToolResult> {
17
+ const action = String(input.action ?? '');
18
+
19
+ try {
20
+ if (action === 'search') {
21
+ const q = String(input.query ?? input.package ?? '');
22
+ if (!q) return { content: 'Error: query required', isError: true };
23
+ const res = await fetch(`https://registry.npmjs.org/-/v1/search?text=${encodeURIComponent(q)}&size=10`);
24
+ const data = await res.json() as { objects?: Array<{ package: { name: string; version: string; description: string } }> };
25
+ const results = (data.objects ?? []).map((o) => `${o.package.name}@${o.package.version} — ${o.package.description}`).join('\n');
26
+ return { content: results || 'No results' };
27
+ }
28
+
29
+ if (action === 'info') {
30
+ const pkg = String(input.package ?? '');
31
+ if (!pkg) return { content: 'Error: package required', isError: true };
32
+ const res = await fetch(`https://registry.npmjs.org/${encodeURIComponent(pkg)}`);
33
+ if (!res.ok) return { content: `Package not found: ${pkg}`, isError: true };
34
+ const data = await res.json() as Record<string, unknown>;
35
+ const latest = (data['dist-tags'] as Record<string, string>)?.latest;
36
+ return { content: `${data.name}@${latest}\n${data.description}\nLicense: ${data.license}\nHomepage: ${data.homepage}` };
37
+ }
38
+
39
+ if (action === 'install') {
40
+ return { content: 'Error: npm install is not supported via this tool for security. Use shell access instead.', isError: true };
41
+ }
42
+
43
+ return { content: `Unknown action: ${action}`, isError: true };
44
+ } catch (err) {
45
+ return { content: `NPM error: ${(err as Error).message}`, isError: true };
46
+ }
47
+ },
48
+ };
@@ -0,0 +1,58 @@
1
+ import type { MCPTool, MCPToolResult } from '../mcp';
2
+ import * as fs from 'fs';
3
+
4
+ export const PDFReaderTool: MCPTool = {
5
+ name: 'pdf-reader',
6
+ description: 'Extract text content from a PDF file. Uses basic binary parsing (no external deps).',
7
+ inputSchema: {
8
+ type: 'object',
9
+ properties: {
10
+ file_path: { type: 'string', description: 'Path to PDF file' },
11
+ url: { type: 'string', description: 'URL of PDF file (alternative to file_path)' },
12
+ max_length: { type: 'number', description: 'Max characters to return (default: 5000)' },
13
+ },
14
+ required: [],
15
+ },
16
+
17
+ async execute(input: Record<string, unknown>): Promise<MCPToolResult> {
18
+ const maxLen = Number(input.max_length ?? 5000);
19
+
20
+ try {
21
+ let buffer: Buffer;
22
+
23
+ if (input.url) {
24
+ const res = await fetch(String(input.url));
25
+ if (!res.ok) return { content: `HTTP ${res.status}`, isError: true };
26
+ buffer = Buffer.from(await res.arrayBuffer());
27
+ } else if (input.file_path) {
28
+ buffer = fs.readFileSync(String(input.file_path));
29
+ } else {
30
+ return { content: 'Error: file_path or url required', isError: true };
31
+ }
32
+
33
+ // Basic PDF text extraction — find text between BT/ET markers and decode
34
+ const content = buffer.toString('latin1');
35
+ const textParts: string[] = [];
36
+
37
+ // Extract text from stream objects
38
+ const streamRegex = /stream\r?\n([\s\S]*?)\r?\nendstream/g;
39
+ let match: RegExpExecArray | null;
40
+ while ((match = streamRegex.exec(content)) !== null) {
41
+ const stream = match[1];
42
+ // Extract text shown with Tj or TJ operators
43
+ const tjRegex = /\(([^)]*)\)\s*Tj/g;
44
+ let tjMatch: RegExpExecArray | null;
45
+ while ((tjMatch = tjRegex.exec(stream)) !== null) {
46
+ textParts.push(tjMatch[1]);
47
+ }
48
+ }
49
+
50
+ const text = textParts.join(' ').replace(/\\n/g, '\n').replace(/\\\(/g, '(').replace(/\\\)/g, ')');
51
+ if (!text.trim()) return { content: '(No extractable text found — PDF may use compressed streams. Consider using a dedicated PDF library.)' };
52
+
53
+ return { content: text.slice(0, maxLen), metadata: { pages_approx: (content.match(/\/Type\s*\/Page[^s]/g) || []).length } };
54
+ } catch (err) {
55
+ return { content: `PDF error: ${(err as Error).message}`, isError: true };
56
+ }
57
+ },
58
+ };
@@ -0,0 +1,65 @@
1
+ import type { MCPTool, MCPToolResult } from '../mcp';
2
+
3
+ export const SlackTool: MCPTool = {
4
+ name: 'slack',
5
+ description: 'Send messages to Slack channels, list channels, or search messages. Requires SLACK_WEBHOOK_URL or SLACK_BOT_TOKEN env var.',
6
+ inputSchema: {
7
+ type: 'object',
8
+ properties: {
9
+ action: { type: 'string', enum: ['send_message', 'list_channels', 'search'], description: 'Action to perform' },
10
+ channel: { type: 'string', description: 'Channel name or ID (for send_message)' },
11
+ text: { type: 'string', description: 'Message text (for send_message) or search query (for search)' },
12
+ },
13
+ required: ['action'],
14
+ },
15
+
16
+ async execute(input: Record<string, unknown>): Promise<MCPToolResult> {
17
+ const action = String(input.action ?? '');
18
+ const token = process.env.SLACK_BOT_TOKEN;
19
+ const webhookUrl = process.env.SLACK_WEBHOOK_URL;
20
+
21
+ try {
22
+ if (action === 'send_message') {
23
+ if (!input.text) return { content: 'Error: text is required', isError: true };
24
+ if (webhookUrl) {
25
+ const res = await fetch(webhookUrl, {
26
+ method: 'POST',
27
+ headers: { 'Content-Type': 'application/json' },
28
+ body: JSON.stringify({ channel: input.channel, text: input.text }),
29
+ });
30
+ return { content: `Message sent (status: ${res.status})` };
31
+ }
32
+ if (!token) return { content: 'Error: SLACK_BOT_TOKEN or SLACK_WEBHOOK_URL required', isError: true };
33
+ const res = await fetch('https://slack.com/api/chat.postMessage', {
34
+ method: 'POST',
35
+ headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
36
+ body: JSON.stringify({ channel: input.channel, text: input.text }),
37
+ });
38
+ const data = await res.json() as Record<string, unknown>;
39
+ return { content: data.ok ? 'Message sent' : `Error: ${data.error}`, isError: !data.ok };
40
+ }
41
+
42
+ if (action === 'list_channels') {
43
+ if (!token) return { content: 'Error: SLACK_BOT_TOKEN required', isError: true };
44
+ const res = await fetch('https://slack.com/api/conversations.list', {
45
+ headers: { 'Authorization': `Bearer ${token}` },
46
+ });
47
+ const data = await res.json() as Record<string, unknown>;
48
+ return { content: JSON.stringify(data, null, 2) };
49
+ }
50
+
51
+ if (action === 'search') {
52
+ if (!token) return { content: 'Error: SLACK_BOT_TOKEN required', isError: true };
53
+ const res = await fetch(`https://slack.com/api/search.messages?query=${encodeURIComponent(String(input.text ?? ''))}`, {
54
+ headers: { 'Authorization': `Bearer ${token}` },
55
+ });
56
+ const data = await res.json() as Record<string, unknown>;
57
+ return { content: JSON.stringify(data, null, 2) };
58
+ }
59
+
60
+ return { content: `Unknown action: ${action}`, isError: true };
61
+ } catch (err) {
62
+ return { content: `Slack error: ${(err as Error).message}`, isError: true };
63
+ }
64
+ },
65
+ };
@@ -0,0 +1,49 @@
1
+ import type { MCPTool, MCPToolResult } from '../mcp';
2
+
3
+ export const SummarizerTool: MCPTool = {
4
+ name: 'summarizer',
5
+ description: 'Summarize long text using an LLM API. Requires OPENAI_API_KEY or LLM_API_URL env var.',
6
+ inputSchema: {
7
+ type: 'object',
8
+ properties: {
9
+ text: { type: 'string', description: 'Text to summarize' },
10
+ max_length: { type: 'number', description: 'Approximate max summary length in words (default: 200)' },
11
+ style: { type: 'string', enum: ['brief', 'detailed', 'bullets'], description: 'Summary style (default: brief)' },
12
+ },
13
+ required: ['text'],
14
+ },
15
+
16
+ async execute(input: Record<string, unknown>): Promise<MCPToolResult> {
17
+ const text = String(input.text ?? '');
18
+ if (!text) return { content: 'Error: text required', isError: true };
19
+
20
+ const style = String(input.style ?? 'brief');
21
+ const maxLen = Number(input.max_length ?? 200);
22
+ const prompt = `Summarize the following text in a ${style} style, approximately ${maxLen} words:\n\n${text.slice(0, 15000)}`;
23
+
24
+ try {
25
+ const apiKey = process.env.OPENAI_API_KEY;
26
+ const apiUrl = process.env.LLM_API_URL || 'https://api.openai.com/v1/chat/completions';
27
+ if (!apiKey && apiUrl === 'https://api.openai.com/v1/chat/completions') {
28
+ return { content: 'Error: OPENAI_API_KEY or LLM_API_URL required', isError: true };
29
+ }
30
+
31
+ const headers: Record<string, string> = { 'Content-Type': 'application/json' };
32
+ if (apiKey) headers['Authorization'] = `Bearer ${apiKey}`;
33
+
34
+ const res = await fetch(apiUrl, {
35
+ method: 'POST', headers,
36
+ body: JSON.stringify({
37
+ model: process.env.LLM_MODEL || 'gpt-4o-mini',
38
+ messages: [{ role: 'user', content: prompt }],
39
+ max_tokens: maxLen * 3,
40
+ }),
41
+ });
42
+ const data = await res.json() as { choices?: Array<{ message: { content: string } }> };
43
+ const summary = data.choices?.[0]?.message?.content ?? 'No summary generated';
44
+ return { content: summary };
45
+ } catch (err) {
46
+ return { content: `Summarizer error: ${(err as Error).message}`, isError: true };
47
+ }
48
+ },
49
+ };
@@ -0,0 +1,48 @@
1
+ import type { MCPTool, MCPToolResult } from '../mcp';
2
+
3
+ export const TranslatorTool: MCPTool = {
4
+ name: 'translator',
5
+ description: 'Translate text between languages using an LLM. Requires OPENAI_API_KEY or LLM_API_URL env var.',
6
+ inputSchema: {
7
+ type: 'object',
8
+ properties: {
9
+ text: { type: 'string', description: 'Text to translate' },
10
+ from: { type: 'string', description: 'Source language (auto-detect if omitted)' },
11
+ to: { type: 'string', description: 'Target language (required)' },
12
+ },
13
+ required: ['text', 'to'],
14
+ },
15
+
16
+ async execute(input: Record<string, unknown>): Promise<MCPToolResult> {
17
+ const text = String(input.text ?? '');
18
+ const to = String(input.to ?? '');
19
+ if (!text || !to) return { content: 'Error: text and to are required', isError: true };
20
+
21
+ const from = input.from ? ` from ${input.from}` : '';
22
+ const prompt = `Translate the following text${from} to ${to}. Return only the translation, no explanations:\n\n${text.slice(0, 10000)}`;
23
+
24
+ try {
25
+ const apiKey = process.env.OPENAI_API_KEY;
26
+ const apiUrl = process.env.LLM_API_URL || 'https://api.openai.com/v1/chat/completions';
27
+ if (!apiKey && apiUrl === 'https://api.openai.com/v1/chat/completions') {
28
+ return { content: 'Error: OPENAI_API_KEY or LLM_API_URL required', isError: true };
29
+ }
30
+
31
+ const headers: Record<string, string> = { 'Content-Type': 'application/json' };
32
+ if (apiKey) headers['Authorization'] = `Bearer ${apiKey}`;
33
+
34
+ const res = await fetch(apiUrl, {
35
+ method: 'POST', headers,
36
+ body: JSON.stringify({
37
+ model: process.env.LLM_MODEL || 'gpt-4o-mini',
38
+ messages: [{ role: 'user', content: prompt }],
39
+ }),
40
+ });
41
+ const data = await res.json() as { choices?: Array<{ message: { content: string } }> };
42
+ const translation = data.choices?.[0]?.message?.content ?? 'No translation generated';
43
+ return { content: translation };
44
+ } catch (err) {
45
+ return { content: `Translation error: ${(err as Error).message}`, isError: true };
46
+ }
47
+ },
48
+ };
@@ -0,0 +1,60 @@
1
+ import type { MCPTool, MCPToolResult } from '../mcp';
2
+
3
+ export const TrelloTool: MCPTool = {
4
+ name: 'trello',
5
+ description: 'Interact with Trello: create cards, move cards, list boards. Requires TRELLO_API_KEY, TRELLO_TOKEN env vars.',
6
+ inputSchema: {
7
+ type: 'object',
8
+ properties: {
9
+ action: { type: 'string', enum: ['create_card', 'move_card', 'list_boards'], description: 'Action' },
10
+ list_id: { type: 'string', description: 'List ID (for create_card/move_card)' },
11
+ card_id: { type: 'string', description: 'Card ID (for move_card)' },
12
+ name: { type: 'string', description: 'Card name' },
13
+ description: { type: 'string', description: 'Card description' },
14
+ },
15
+ required: ['action'],
16
+ },
17
+
18
+ async execute(input: Record<string, unknown>): Promise<MCPToolResult> {
19
+ const key = process.env.TRELLO_API_KEY;
20
+ const token = process.env.TRELLO_TOKEN;
21
+ if (!key || !token) return { content: 'Error: TRELLO_API_KEY, TRELLO_TOKEN required', isError: true };
22
+
23
+ const auth = `key=${key}&token=${token}`;
24
+ const action = String(input.action ?? '');
25
+
26
+ try {
27
+ if (action === 'create_card') {
28
+ if (!input.list_id || !input.name) return { content: 'Error: list_id, name required', isError: true };
29
+ const res = await fetch(`https://api.trello.com/1/cards?${auth}`, {
30
+ method: 'POST',
31
+ headers: { 'Content-Type': 'application/json' },
32
+ body: JSON.stringify({ idList: input.list_id, name: input.name, desc: input.description ?? '' }),
33
+ });
34
+ const data = await res.json() as Record<string, unknown>;
35
+ return { content: `Card created: ${data.shortUrl ?? data.id}` };
36
+ }
37
+
38
+ if (action === 'move_card') {
39
+ if (!input.card_id || !input.list_id) return { content: 'Error: card_id, list_id required', isError: true };
40
+ await fetch(`https://api.trello.com/1/cards/${input.card_id}?${auth}`, {
41
+ method: 'PUT',
42
+ headers: { 'Content-Type': 'application/json' },
43
+ body: JSON.stringify({ idList: input.list_id }),
44
+ });
45
+ return { content: `Card ${input.card_id} moved to list ${input.list_id}` };
46
+ }
47
+
48
+ if (action === 'list_boards') {
49
+ const res = await fetch(`https://api.trello.com/1/members/me/boards?${auth}`);
50
+ const data = await res.json() as Array<Record<string, unknown>>;
51
+ const summary = Array.isArray(data) ? data.map((b) => `${b.name} (${b.id})`).join('\n') : JSON.stringify(data);
52
+ return { content: summary };
53
+ }
54
+
55
+ return { content: `Unknown action: ${action}`, isError: true };
56
+ } catch (err) {
57
+ return { content: `Trello error: ${(err as Error).message}`, isError: true };
58
+ }
59
+ },
60
+ };
@@ -0,0 +1,42 @@
1
+ import type { MCPTool, MCPToolResult } from '../mcp';
2
+
3
+ export const VectorSearchTool: MCPTool = {
4
+ name: 'vector-search',
5
+ description: 'Search vector embeddings via DeepBrain or compatible API. Requires DEEPBRAIN_URL and DEEPBRAIN_API_KEY env vars.',
6
+ inputSchema: {
7
+ type: 'object',
8
+ properties: {
9
+ query: { type: 'string', description: 'Search query text' },
10
+ collection: { type: 'string', description: 'Collection/namespace to search' },
11
+ top_k: { type: 'number', description: 'Number of results (default: 5)' },
12
+ },
13
+ required: ['query'],
14
+ },
15
+
16
+ async execute(input: Record<string, unknown>): Promise<MCPToolResult> {
17
+ const baseUrl = process.env.DEEPBRAIN_URL;
18
+ const apiKey = process.env.DEEPBRAIN_API_KEY;
19
+ if (!baseUrl) return { content: 'Error: DEEPBRAIN_URL required', isError: true };
20
+
21
+ const query = String(input.query ?? '');
22
+ if (!query) return { content: 'Error: query required', isError: true };
23
+
24
+ try {
25
+ const headers: Record<string, string> = { 'Content-Type': 'application/json' };
26
+ if (apiKey) headers['Authorization'] = `Bearer ${apiKey}`;
27
+
28
+ const res = await fetch(`${baseUrl}/api/search`, {
29
+ method: 'POST', headers,
30
+ body: JSON.stringify({
31
+ query,
32
+ collection: input.collection ?? 'default',
33
+ top_k: Number(input.top_k ?? 5),
34
+ }),
35
+ });
36
+ const data = await res.json() as Record<string, unknown>;
37
+ return { content: JSON.stringify(data, null, 2).slice(0, 4000) };
38
+ } catch (err) {
39
+ return { content: `Vector search error: ${(err as Error).message}`, isError: true };
40
+ }
41
+ },
42
+ };
@@ -0,0 +1,47 @@
1
+ import type { MCPTool, MCPToolResult } from '../mcp';
2
+
3
+ export const WebScraperTool: MCPTool = {
4
+ name: 'web-scraper',
5
+ description: 'Fetch and extract readable content from a URL.',
6
+ inputSchema: {
7
+ type: 'object',
8
+ properties: {
9
+ url: { type: 'string', description: 'URL to scrape' },
10
+ max_length: { type: 'number', description: 'Max characters to return (default: 5000)' },
11
+ },
12
+ required: ['url'],
13
+ },
14
+
15
+ async execute(input: Record<string, unknown>): Promise<MCPToolResult> {
16
+ const url = String(input.url ?? '');
17
+ if (!url) return { content: 'Error: url required', isError: true };
18
+ const maxLen = Number(input.max_length ?? 5000);
19
+
20
+ try {
21
+ const res = await fetch(url, {
22
+ headers: { 'User-Agent': 'Mozilla/5.0 (compatible; OPCAgent/1.0)' },
23
+ });
24
+ if (!res.ok) return { content: `HTTP ${res.status}: ${res.statusText}`, isError: true };
25
+
26
+ const html = await res.text();
27
+ // Simple HTML to text extraction
28
+ const text = html
29
+ .replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
30
+ .replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
31
+ .replace(/<[^>]+>/g, ' ')
32
+ .replace(/&nbsp;/g, ' ')
33
+ .replace(/&amp;/g, '&')
34
+ .replace(/&lt;/g, '<')
35
+ .replace(/&gt;/g, '>')
36
+ .replace(/&quot;/g, '"')
37
+ .replace(/&#39;/g, "'")
38
+ .replace(/\s+/g, ' ')
39
+ .trim();
40
+
41
+ const truncated = text.length > maxLen ? text.slice(0, maxLen) + '...(truncated)' : text;
42
+ return { content: truncated, metadata: { url, length: text.length } };
43
+ } catch (err) {
44
+ return { content: `Scraper error: ${(err as Error).message}`, isError: true };
45
+ }
46
+ },
47
+ };
@@ -0,0 +1,58 @@
1
+ import type { MCPTool, MCPToolResult } from '../mcp';
2
+
3
+ export const WebSearchTool: MCPTool = {
4
+ name: 'web-search',
5
+ description: 'Search the web using SerpAPI, Tavily, or Brave Search. Requires SERPAPI_KEY, TAVILY_API_KEY, or BRAVE_SEARCH_KEY env var.',
6
+ inputSchema: {
7
+ type: 'object',
8
+ properties: {
9
+ query: { type: 'string', description: 'Search query' },
10
+ provider: { type: 'string', enum: ['serpapi', 'tavily', 'brave'], description: 'Search provider (auto-detects from env)' },
11
+ count: { type: 'number', description: 'Number of results (default: 5)' },
12
+ },
13
+ required: ['query'],
14
+ },
15
+
16
+ async execute(input: Record<string, unknown>): Promise<MCPToolResult> {
17
+ const query = String(input.query ?? '');
18
+ if (!query) return { content: 'Error: query required', isError: true };
19
+ const count = Number(input.count ?? 5);
20
+
21
+ try {
22
+ const provider = String(input.provider ?? '');
23
+ if (provider === 'tavily' || process.env.TAVILY_API_KEY) {
24
+ const key = process.env.TAVILY_API_KEY;
25
+ if (!key) return { content: 'Error: TAVILY_API_KEY required', isError: true };
26
+ const res = await fetch('https://api.tavily.com/search', {
27
+ method: 'POST',
28
+ headers: { 'Content-Type': 'application/json' },
29
+ body: JSON.stringify({ api_key: key, query, max_results: count }),
30
+ });
31
+ const data = await res.json() as Record<string, unknown>;
32
+ return { content: JSON.stringify(data, null, 2).slice(0, 4000) };
33
+ }
34
+
35
+ if (provider === 'brave' || process.env.BRAVE_SEARCH_KEY) {
36
+ const key = process.env.BRAVE_SEARCH_KEY;
37
+ if (!key) return { content: 'Error: BRAVE_SEARCH_KEY required', isError: true };
38
+ const res = await fetch(`https://api.search.brave.com/res/v1/web/search?q=${encodeURIComponent(query)}&count=${count}`, {
39
+ headers: { 'X-Subscription-Token': key, 'Accept': 'application/json' },
40
+ });
41
+ const data = await res.json() as Record<string, unknown>;
42
+ return { content: JSON.stringify(data, null, 2).slice(0, 4000) };
43
+ }
44
+
45
+ if (provider === 'serpapi' || process.env.SERPAPI_KEY) {
46
+ const key = process.env.SERPAPI_KEY;
47
+ if (!key) return { content: 'Error: SERPAPI_KEY required', isError: true };
48
+ const res = await fetch(`https://serpapi.com/search.json?q=${encodeURIComponent(query)}&num=${count}&api_key=${key}`);
49
+ const data = await res.json() as Record<string, unknown>;
50
+ return { content: JSON.stringify(data, null, 2).slice(0, 4000) };
51
+ }
52
+
53
+ return { content: 'Error: No search API key configured (TAVILY_API_KEY, BRAVE_SEARCH_KEY, or SERPAPI_KEY)', isError: true };
54
+ } catch (err) {
55
+ return { content: `Search error: ${(err as Error).message}`, isError: true };
56
+ }
57
+ },
58
+ };