lark-billing-mcp 0.7.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 (94) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +99 -0
  3. package/code-tool-types.d.mts +13 -0
  4. package/code-tool-types.d.mts.map +1 -0
  5. package/code-tool-types.d.ts +13 -0
  6. package/code-tool-types.d.ts.map +1 -0
  7. package/code-tool-types.js +4 -0
  8. package/code-tool-types.js.map +1 -0
  9. package/code-tool-types.mjs +3 -0
  10. package/code-tool-types.mjs.map +1 -0
  11. package/code-tool.d.mts +12 -0
  12. package/code-tool.d.mts.map +1 -0
  13. package/code-tool.d.ts +12 -0
  14. package/code-tool.d.ts.map +1 -0
  15. package/code-tool.js +85 -0
  16. package/code-tool.js.map +1 -0
  17. package/code-tool.mjs +82 -0
  18. package/code-tool.mjs.map +1 -0
  19. package/docs-search-tool.d.mts +50 -0
  20. package/docs-search-tool.d.mts.map +1 -0
  21. package/docs-search-tool.d.ts +50 -0
  22. package/docs-search-tool.d.ts.map +1 -0
  23. package/docs-search-tool.js +51 -0
  24. package/docs-search-tool.js.map +1 -0
  25. package/docs-search-tool.mjs +47 -0
  26. package/docs-search-tool.mjs.map +1 -0
  27. package/headers.d.mts +4 -0
  28. package/headers.d.mts.map +1 -0
  29. package/headers.d.ts +4 -0
  30. package/headers.d.ts.map +1 -0
  31. package/headers.js +10 -0
  32. package/headers.js.map +1 -0
  33. package/headers.mjs +6 -0
  34. package/headers.mjs.map +1 -0
  35. package/http.d.mts +9 -0
  36. package/http.d.mts.map +1 -0
  37. package/http.d.ts +9 -0
  38. package/http.d.ts.map +1 -0
  39. package/http.js +91 -0
  40. package/http.js.map +1 -0
  41. package/http.mjs +83 -0
  42. package/http.mjs.map +1 -0
  43. package/index.d.mts +3 -0
  44. package/index.d.mts.map +1 -0
  45. package/index.d.ts +3 -0
  46. package/index.d.ts.map +1 -0
  47. package/index.js +55 -0
  48. package/index.js.map +1 -0
  49. package/index.mjs +53 -0
  50. package/index.mjs.map +1 -0
  51. package/options.d.mts +11 -0
  52. package/options.d.mts.map +1 -0
  53. package/options.d.ts +11 -0
  54. package/options.d.ts.map +1 -0
  55. package/options.js +72 -0
  56. package/options.js.map +1 -0
  57. package/options.mjs +65 -0
  58. package/options.mjs.map +1 -0
  59. package/package.json +161 -0
  60. package/server.d.mts +30 -0
  61. package/server.d.mts.map +1 -0
  62. package/server.d.ts +30 -0
  63. package/server.d.ts.map +1 -0
  64. package/server.js +121 -0
  65. package/server.js.map +1 -0
  66. package/server.mjs +109 -0
  67. package/server.mjs.map +1 -0
  68. package/src/code-tool-types.ts +15 -0
  69. package/src/code-tool.ts +96 -0
  70. package/src/docs-search-tool.ts +59 -0
  71. package/src/headers.ts +10 -0
  72. package/src/http.ts +109 -0
  73. package/src/index.ts +61 -0
  74. package/src/options.ts +92 -0
  75. package/src/server.ts +147 -0
  76. package/src/stdio.ts +12 -0
  77. package/src/tsconfig.json +11 -0
  78. package/src/types.ts +115 -0
  79. package/stdio.d.mts +2 -0
  80. package/stdio.d.mts.map +1 -0
  81. package/stdio.d.ts +2 -0
  82. package/stdio.d.ts.map +1 -0
  83. package/stdio.js +14 -0
  84. package/stdio.js.map +1 -0
  85. package/stdio.mjs +10 -0
  86. package/stdio.mjs.map +1 -0
  87. package/types.d.mts +52 -0
  88. package/types.d.mts.map +1 -0
  89. package/types.d.ts +52 -0
  90. package/types.d.ts.map +1 -0
  91. package/types.js +58 -0
  92. package/types.js.map +1 -0
  93. package/types.mjs +53 -0
  94. package/types.mjs.map +1 -0
@@ -0,0 +1,96 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { McpTool, Metadata, ToolCallResult, asErrorResult, asTextContentResult } from './types';
4
+ import { Tool } from '@modelcontextprotocol/sdk/types.js';
5
+ import { readEnv, readEnvOrError } from './server';
6
+ import { WorkerInput, WorkerOutput } from './code-tool-types';
7
+
8
+ const prompt = `Runs JavaScript code to interact with the Lark API.
9
+
10
+ You are a skilled programmer writing code to interface with the service.
11
+ Define an async function named "run" that takes a single parameter of an initialized SDK client and it will be run.
12
+ For example:
13
+
14
+ \`\`\`
15
+ async function run(client) {
16
+ const subject = await client.subjects.create({
17
+ email: 'john.doe@example.com',
18
+ external_id: 'user_1234567890',
19
+ name: 'John Doe',
20
+ });
21
+
22
+ console.log(subject.id);
23
+ }
24
+ \`\`\`
25
+
26
+ You will be returned anything that your function returns, plus the results of any console.log statements.
27
+ Do not add try-catch blocks for single API calls. The tool will handle errors for you.
28
+ Do not add comments unless necessary for generating better code.
29
+ Code will run in a container, and cannot interact with the network outside of the given SDK client.
30
+ Variables will not persist between calls, so make sure to return or log any data you might need later.`;
31
+
32
+ /**
33
+ * A tool that runs code against a copy of the SDK.
34
+ *
35
+ * Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
36
+ * we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
37
+ * a generic endpoint that can be used to invoke any endpoint with the provided arguments.
38
+ *
39
+ * @param endpoints - The endpoints to include in the list.
40
+ */
41
+ export function codeTool(): McpTool {
42
+ const metadata: Metadata = { resource: 'all', operation: 'write', tags: [] };
43
+ const tool: Tool = {
44
+ name: 'execute',
45
+ description: prompt,
46
+ inputSchema: { type: 'object', properties: { code: { type: 'string' } } },
47
+ };
48
+ const handler = async (_: unknown, args: any): Promise<ToolCallResult> => {
49
+ const code = args.code as string;
50
+
51
+ // this is not required, but passing a Stainless API key for the matching project_name
52
+ // will allow you to run code-mode queries against non-published versions of your SDK.
53
+ const stainlessAPIKey = readEnv('STAINLESS_API_KEY');
54
+ const codeModeEndpoint =
55
+ readEnv('CODE_MODE_ENDPOINT_URL') ?? 'https://api.stainless.com/api/ai/code-tool';
56
+
57
+ const res = await fetch(codeModeEndpoint, {
58
+ method: 'POST',
59
+ headers: {
60
+ ...(stainlessAPIKey && { Authorization: stainlessAPIKey }),
61
+ 'Content-Type': 'application/json',
62
+ client_envs: JSON.stringify({
63
+ LARK_API_KEY: readEnvOrError('LARK_API_KEY'),
64
+ LARK_BASE_URL: readEnv('LARK_BASE_URL'),
65
+ }),
66
+ },
67
+ body: JSON.stringify({
68
+ project_name: 'lark',
69
+ code,
70
+ client_opts: {},
71
+ } satisfies WorkerInput),
72
+ });
73
+
74
+ if (!res.ok) {
75
+ throw new Error(
76
+ `${res.status}: ${
77
+ res.statusText
78
+ } error when trying to contact Code Tool server. Details: ${await res.text()}`,
79
+ );
80
+ }
81
+
82
+ const { is_error, result, log_lines, err_lines } = (await res.json()) as WorkerOutput;
83
+ const hasLogs = log_lines.length > 0 || err_lines.length > 0;
84
+ const output = {
85
+ result,
86
+ ...(log_lines.length > 0 && { log_lines }),
87
+ ...(err_lines.length > 0 && { err_lines }),
88
+ };
89
+ if (is_error) {
90
+ return asErrorResult(typeof result === 'string' && !hasLogs ? result : JSON.stringify(output, null, 2));
91
+ }
92
+ return asTextContentResult(output);
93
+ };
94
+
95
+ return { metadata, tool, handler };
96
+ }
@@ -0,0 +1,59 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { Metadata, asTextContentResult } from './types';
4
+
5
+ import { Tool } from '@modelcontextprotocol/sdk/types.js';
6
+
7
+ export const metadata: Metadata = {
8
+ resource: 'all',
9
+ operation: 'read',
10
+ tags: [],
11
+ httpMethod: 'get',
12
+ };
13
+
14
+ export const tool: Tool = {
15
+ name: 'search_docs',
16
+ description: 'Search for documentation for how to use the client to interact with the API.',
17
+ inputSchema: {
18
+ type: 'object',
19
+ properties: {
20
+ query: {
21
+ type: 'string',
22
+ description: 'The query to search for.',
23
+ },
24
+ language: {
25
+ type: 'string',
26
+ description: 'The language for the SDK to search for.',
27
+ enum: ['http', 'python', 'go', 'typescript', 'javascript', 'terraform', 'ruby', 'java', 'kotlin'],
28
+ },
29
+ detail: {
30
+ type: 'string',
31
+ description: 'The amount of detail to return.',
32
+ enum: ['default', 'verbose'],
33
+ },
34
+ },
35
+ required: ['query', 'language'],
36
+ },
37
+ annotations: {
38
+ readOnlyHint: true,
39
+ },
40
+ };
41
+
42
+ const docsSearchURL =
43
+ process.env['DOCS_SEARCH_URL'] || 'https://api.stainless.com/api/projects/lark/docs/search';
44
+
45
+ export const handler = async (_: unknown, args: Record<string, unknown> | undefined) => {
46
+ const body = args as any;
47
+ const query = new URLSearchParams(body).toString();
48
+ const result = await fetch(`${docsSearchURL}?${query}`);
49
+
50
+ if (!result.ok) {
51
+ throw new Error(
52
+ `${result.status}: ${result.statusText} when using doc search tool. Details: ${await result.text()}`,
53
+ );
54
+ }
55
+
56
+ return asTextContentResult(await result.json());
57
+ };
58
+
59
+ export default { metadata, tool, handler };
package/src/headers.ts ADDED
@@ -0,0 +1,10 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { IncomingMessage } from 'node:http';
4
+ import { ClientOptions } from 'lark-billing';
5
+
6
+ export const parseAuthHeaders = (req: IncomingMessage): Partial<ClientOptions> => {
7
+ const apiKey =
8
+ Array.isArray(req.headers['x-api-key']) ? req.headers['x-api-key'][0] : req.headers['x-api-key'];
9
+ return { apiKey };
10
+ };
package/src/http.ts ADDED
@@ -0,0 +1,109 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
4
+ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
5
+
6
+ import express from 'express';
7
+ import { McpOptions } from './options';
8
+ import { ClientOptions, initMcpServer, newMcpServer } from './server';
9
+ import { parseAuthHeaders } from './headers';
10
+
11
+ const newServer = ({
12
+ clientOptions,
13
+ req,
14
+ res,
15
+ }: {
16
+ clientOptions: ClientOptions;
17
+ req: express.Request;
18
+ res: express.Response;
19
+ }): McpServer | null => {
20
+ const server = newMcpServer();
21
+
22
+ try {
23
+ const authOptions = parseAuthHeaders(req);
24
+ initMcpServer({
25
+ server: server,
26
+ clientOptions: {
27
+ ...clientOptions,
28
+ ...authOptions,
29
+ },
30
+ });
31
+ } catch (error) {
32
+ res.status(401).json({
33
+ jsonrpc: '2.0',
34
+ error: {
35
+ code: -32000,
36
+ message: `Unauthorized: ${error instanceof Error ? error.message : error}`,
37
+ },
38
+ });
39
+ return null;
40
+ }
41
+
42
+ return server;
43
+ };
44
+
45
+ const post =
46
+ (options: { clientOptions: ClientOptions; mcpOptions: McpOptions }) =>
47
+ async (req: express.Request, res: express.Response) => {
48
+ const server = newServer({ ...options, req, res });
49
+ // If we return null, we already set the authorization error.
50
+ if (server === null) return;
51
+ const transport = new StreamableHTTPServerTransport({
52
+ // Stateless server
53
+ sessionIdGenerator: undefined,
54
+ });
55
+ await server.connect(transport);
56
+ await transport.handleRequest(req, res, req.body);
57
+ };
58
+
59
+ const get = async (req: express.Request, res: express.Response) => {
60
+ res.status(405).json({
61
+ jsonrpc: '2.0',
62
+ error: {
63
+ code: -32000,
64
+ message: 'Method not supported',
65
+ },
66
+ });
67
+ };
68
+
69
+ const del = async (req: express.Request, res: express.Response) => {
70
+ res.status(405).json({
71
+ jsonrpc: '2.0',
72
+ error: {
73
+ code: -32000,
74
+ message: 'Method not supported',
75
+ },
76
+ });
77
+ };
78
+
79
+ export const streamableHTTPApp = ({
80
+ clientOptions = {},
81
+ mcpOptions = {},
82
+ }: {
83
+ clientOptions?: ClientOptions;
84
+ mcpOptions?: McpOptions;
85
+ }): express.Express => {
86
+ const app = express();
87
+ app.set('query parser', 'extended');
88
+ app.use(express.json());
89
+
90
+ app.get('/', get);
91
+ app.post('/', post({ clientOptions, mcpOptions }));
92
+ app.delete('/', del);
93
+
94
+ return app;
95
+ };
96
+
97
+ export const launchStreamableHTTPServer = async (options: McpOptions, port: number | string | undefined) => {
98
+ const app = streamableHTTPApp({ mcpOptions: options });
99
+ const server = app.listen(port);
100
+ const address = server.address();
101
+
102
+ if (typeof address === 'string') {
103
+ console.error(`MCP Server running on streamable HTTP at ${address}`);
104
+ } else if (address !== null) {
105
+ console.error(`MCP Server running on streamable HTTP on port ${address.port}`);
106
+ } else {
107
+ console.error(`MCP Server running on streamable HTTP on port ${port}`);
108
+ }
109
+ };
package/src/index.ts ADDED
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { selectTools } from './server';
4
+ import { McpOptions, parseCLIOptions } from './options';
5
+ import { launchStdioServer } from './stdio';
6
+ import { launchStreamableHTTPServer } from './http';
7
+ import type { McpTool } from './types';
8
+
9
+ async function main() {
10
+ const options = parseOptionsOrError();
11
+
12
+ const selectedTools = await selectToolsOrError(options);
13
+
14
+ console.error(
15
+ `MCP Server starting with ${selectedTools.length} tools:`,
16
+ selectedTools.map((e) => e.tool.name),
17
+ );
18
+
19
+ switch (options.transport) {
20
+ case 'stdio':
21
+ await launchStdioServer();
22
+ break;
23
+ case 'http':
24
+ await launchStreamableHTTPServer(options, options.port ?? options.socket);
25
+ break;
26
+ }
27
+ }
28
+
29
+ if (require.main === module) {
30
+ main().catch((error) => {
31
+ console.error('Fatal error in main():', error);
32
+ process.exit(1);
33
+ });
34
+ }
35
+
36
+ function parseOptionsOrError() {
37
+ try {
38
+ return parseCLIOptions();
39
+ } catch (error) {
40
+ console.error('Error parsing options:', error);
41
+ process.exit(1);
42
+ }
43
+ }
44
+
45
+ async function selectToolsOrError(options: McpOptions): Promise<McpTool[]> {
46
+ try {
47
+ const includedTools = selectTools(options);
48
+ if (includedTools.length === 0) {
49
+ console.error('No tools match the provided filters.');
50
+ process.exit(1);
51
+ }
52
+ return includedTools;
53
+ } catch (error) {
54
+ if (error instanceof Error) {
55
+ console.error('Error filtering tools:', error.message);
56
+ } else {
57
+ console.error('Error filtering tools:', error);
58
+ }
59
+ process.exit(1);
60
+ }
61
+ }
package/src/options.ts ADDED
@@ -0,0 +1,92 @@
1
+ import qs from 'qs';
2
+ import yargs from 'yargs';
3
+ import { hideBin } from 'yargs/helpers';
4
+ import z from 'zod';
5
+
6
+ export type CLIOptions = McpOptions & {
7
+ transport: 'stdio' | 'http';
8
+ port: number | undefined;
9
+ socket: string | undefined;
10
+ };
11
+
12
+ export type McpOptions = {
13
+ includeDocsTools?: boolean | undefined;
14
+ };
15
+
16
+ export function parseCLIOptions(): CLIOptions {
17
+ const opts = yargs(hideBin(process.argv))
18
+ .option('tools', {
19
+ type: 'string',
20
+ array: true,
21
+ choices: ['code', 'docs'],
22
+ description: 'Use dynamic tools or all tools',
23
+ })
24
+ .option('no-tools', {
25
+ type: 'string',
26
+ array: true,
27
+ choices: ['code', 'docs'],
28
+ description: 'Do not use any dynamic or all tools',
29
+ })
30
+ .option('transport', {
31
+ type: 'string',
32
+ choices: ['stdio', 'http'],
33
+ default: 'stdio',
34
+ description: 'What transport to use; stdio for local servers or http for remote servers',
35
+ })
36
+ .option('port', {
37
+ type: 'number',
38
+ description: 'Port to serve on if using http transport',
39
+ })
40
+ .option('socket', {
41
+ type: 'string',
42
+ description: 'Unix socket to serve on if using http transport',
43
+ })
44
+ .help();
45
+
46
+ const argv = opts.parseSync();
47
+
48
+ const shouldIncludeToolType = (toolType: 'code' | 'docs') =>
49
+ argv.noTools?.includes(toolType) ? false
50
+ : argv.tools?.includes(toolType) ? true
51
+ : undefined;
52
+
53
+ const includeDocsTools = shouldIncludeToolType('docs');
54
+
55
+ const transport = argv.transport as 'stdio' | 'http';
56
+
57
+ return {
58
+ ...(includeDocsTools !== undefined && { includeDocsTools }),
59
+ transport,
60
+ port: argv.port,
61
+ socket: argv.socket,
62
+ };
63
+ }
64
+
65
+ const coerceArray = <T extends z.ZodTypeAny>(zodType: T) =>
66
+ z.preprocess(
67
+ (val) =>
68
+ Array.isArray(val) ? val
69
+ : val ? [val]
70
+ : val,
71
+ z.array(zodType).optional(),
72
+ );
73
+
74
+ const QueryOptions = z.object({
75
+ tools: coerceArray(z.enum(['code', 'docs'])).describe('Specify which MCP tools to use'),
76
+ no_tools: coerceArray(z.enum(['code', 'docs'])).describe('Specify which MCP tools to not use.'),
77
+ tool: coerceArray(z.string()).describe('Include tools matching the specified names'),
78
+ });
79
+
80
+ export function parseQueryOptions(defaultOptions: McpOptions, query: unknown): McpOptions {
81
+ const queryObject = typeof query === 'string' ? qs.parse(query) : query;
82
+ const queryOptions = QueryOptions.parse(queryObject);
83
+
84
+ let docsTools: boolean | undefined =
85
+ queryOptions.no_tools && queryOptions.no_tools?.includes('docs') ? false
86
+ : queryOptions.tools?.includes('docs') ? true
87
+ : defaultOptions.includeDocsTools;
88
+
89
+ return {
90
+ ...(docsTools !== undefined && { includeDocsTools: docsTools }),
91
+ };
92
+ }
package/src/server.ts ADDED
@@ -0,0 +1,147 @@
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 {
6
+ CallToolRequestSchema,
7
+ ListToolsRequestSchema,
8
+ SetLevelRequestSchema,
9
+ } from '@modelcontextprotocol/sdk/types.js';
10
+ import { ClientOptions } from 'lark-billing';
11
+ import Lark from 'lark-billing';
12
+ import { codeTool } from './code-tool';
13
+ import docsSearchTool from './docs-search-tool';
14
+ import { McpOptions } from './options';
15
+ import { HandlerFunction, McpTool } from './types';
16
+
17
+ export { McpOptions } from './options';
18
+ export { ClientOptions } from 'lark-billing';
19
+
20
+ export const newMcpServer = () =>
21
+ new McpServer(
22
+ {
23
+ name: 'lark_billing_api',
24
+ version: '0.7.0',
25
+ },
26
+ { capabilities: { tools: {}, logging: {} } },
27
+ );
28
+
29
+ // Create server instance
30
+ export const server = newMcpServer();
31
+
32
+ /**
33
+ * Initializes the provided MCP Server with the given tools and handlers.
34
+ * If not provided, the default client, tools and handlers will be used.
35
+ */
36
+ export function initMcpServer(params: {
37
+ server: Server | McpServer;
38
+ clientOptions?: ClientOptions;
39
+ mcpOptions?: McpOptions;
40
+ }) {
41
+ const server = params.server instanceof McpServer ? params.server.server : params.server;
42
+
43
+ const logAtLevel =
44
+ (level: 'debug' | 'info' | 'warning' | 'error') =>
45
+ (message: string, ...rest: unknown[]) => {
46
+ void server.sendLoggingMessage({
47
+ level,
48
+ data: { message, rest },
49
+ });
50
+ };
51
+ const logger = {
52
+ debug: logAtLevel('debug'),
53
+ info: logAtLevel('info'),
54
+ warn: logAtLevel('warning'),
55
+ error: logAtLevel('error'),
56
+ };
57
+
58
+ let client = new Lark({
59
+ logger,
60
+ ...params.clientOptions,
61
+ defaultHeaders: {
62
+ ...params.clientOptions?.defaultHeaders,
63
+ 'X-Stainless-MCP': 'true',
64
+ },
65
+ });
66
+
67
+ const providedTools = selectTools(params.mcpOptions);
68
+ const toolMap = Object.fromEntries(providedTools.map((mcpTool) => [mcpTool.tool.name, mcpTool]));
69
+
70
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
71
+ return {
72
+ tools: providedTools.map((mcpTool) => mcpTool.tool),
73
+ };
74
+ });
75
+
76
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
77
+ const { name, arguments: args } = request.params;
78
+ const mcpTool = toolMap[name];
79
+ if (!mcpTool) {
80
+ throw new Error(`Unknown tool: ${name}`);
81
+ }
82
+
83
+ return executeHandler(mcpTool.handler, client, args);
84
+ });
85
+
86
+ server.setRequestHandler(SetLevelRequestSchema, async (request) => {
87
+ const { level } = request.params;
88
+ switch (level) {
89
+ case 'debug':
90
+ client = client.withOptions({ logLevel: 'debug' });
91
+ break;
92
+ case 'info':
93
+ client = client.withOptions({ logLevel: 'info' });
94
+ break;
95
+ case 'notice':
96
+ case 'warning':
97
+ client = client.withOptions({ logLevel: 'warn' });
98
+ break;
99
+ case 'error':
100
+ client = client.withOptions({ logLevel: 'error' });
101
+ break;
102
+ default:
103
+ client = client.withOptions({ logLevel: 'off' });
104
+ break;
105
+ }
106
+ return {};
107
+ });
108
+ }
109
+
110
+ /**
111
+ * Selects the tools to include in the MCP Server based on the provided options.
112
+ */
113
+ export function selectTools(options?: McpOptions): McpTool[] {
114
+ const includedTools = [codeTool()];
115
+ if (options?.includeDocsTools ?? true) {
116
+ includedTools.push(docsSearchTool);
117
+ }
118
+ return includedTools;
119
+ }
120
+
121
+ /**
122
+ * Runs the provided handler with the given client and arguments.
123
+ */
124
+ export async function executeHandler(
125
+ handler: HandlerFunction,
126
+ client: Lark,
127
+ args: Record<string, unknown> | undefined,
128
+ ) {
129
+ return await handler(client, args || {});
130
+ }
131
+
132
+ export const readEnv = (env: string): string | undefined => {
133
+ if (typeof (globalThis as any).process !== 'undefined') {
134
+ return (globalThis as any).process.env?.[env]?.trim();
135
+ } else if (typeof (globalThis as any).Deno !== 'undefined') {
136
+ return (globalThis as any).Deno.env?.get?.(env)?.trim();
137
+ }
138
+ return;
139
+ };
140
+
141
+ export const readEnvOrError = (env: string): string => {
142
+ let envValue = readEnv(env);
143
+ if (envValue === undefined) {
144
+ throw new Error(`Environment variable ${env} is not set`);
145
+ }
146
+ return envValue;
147
+ };
package/src/stdio.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
2
+ import { initMcpServer, newMcpServer } from './server';
3
+
4
+ export const launchStdioServer = async () => {
5
+ const server = newMcpServer();
6
+
7
+ initMcpServer({ server });
8
+
9
+ const transport = new StdioServerTransport();
10
+ await server.connect(transport);
11
+ console.error('MCP Server running on stdio');
12
+ };
@@ -0,0 +1,11 @@
1
+ {
2
+ // this config is included in the published src directory to prevent TS errors
3
+ // from appearing when users go to source, and VSCode opens the source .ts file
4
+ // via declaration maps
5
+ "include": ["index.ts"],
6
+ "compilerOptions": {
7
+ "target": "es2015",
8
+ "lib": ["DOM"],
9
+ "moduleResolution": "node"
10
+ }
11
+ }