-
Couldn't load subscription status.
- Fork 2
feat: introduce fetchTools
#114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ryoppippi
merged 22 commits into
main
from
ENG-11034-add-dynamic-tool-fetching-via-mcp-in-our-sdk
Oct 8, 2025
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a8e6236
chore(deps): add mcp sdk
ryoppippi 3d210e7
feat: fetchTool
ryoppippi 8916c1e
feat: headers for mcp
ryoppippi dd22858
chore(deps): add stackone client sdk dependency
ryoppippi 562581a
feat: execute stackone tools via actions rpc
ryoppippi aee9231
test: verify fetchTools against hono mcp
ryoppippi 0846baa
Refactor execute config handling
ryoppippi c1d4105
test: move mock
ryoppippi 9ee7d3a
test: update snapshot
ryoppippi a32e6c3
Add inline comments for execution config changes
ryoppippi 7ef126d
Tighten test mock execute config typing
ryoppippi 90cdf03
Document execute config union
ryoppippi b8d71ed
fix: fallback to env api key for actions client
ryoppippi 3e16bdb
docs: document mcp-powered tools
ryoppippi a73b8d0
Revert "docs: document mcp-powered tools"
ryoppippi a30304a
docs: explain fetchTools usage
ryoppippi 8e36061
test: add zod dependency for mcp tests
ryoppippi 4ee7746
fix: typesafe config
ryoppippi 185e5c8
refactor: alias http body type and enforce exhaustive handling
ryoppippi 9137d63
docs: note union exhaustiveness pattern
ryoppippi d66998f
fix: remove default mcp options
ryoppippi 08d1599
chore: note future fetchTools filters
ryoppippi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /** | ||
| * Example: fetch the latest StackOne tool catalog and execute a tool. | ||
| * | ||
| * Set `STACKONE_API_KEY` (and optionally `STACKONE_BASE_URL`) before running. | ||
| * By default the script exits early in test environments where a real key is | ||
| * not available. | ||
| */ | ||
|
|
||
| import process from 'node:process'; | ||
| import { StackOneToolSet } from '../src'; | ||
|
|
||
| const apiKey = process.env.STACKONE_API_KEY; | ||
| const isPlaceholderKey = !apiKey || apiKey === 'test-stackone-key'; | ||
| const shouldSkip = process.env.SKIP_FETCH_TOOLS_EXAMPLE !== '0' && isPlaceholderKey; | ||
|
|
||
| if (shouldSkip) { | ||
| console.log( | ||
| 'Skipping fetch-tools example. Provide STACKONE_API_KEY and set SKIP_FETCH_TOOLS_EXAMPLE=0 to run.' | ||
| ); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| const toolset = new StackOneToolSet({ | ||
| baseUrl: process.env.STACKONE_BASE_URL ?? 'https://api.stackone.com', | ||
| }); | ||
|
|
||
| const tools = await toolset.fetchTools(); | ||
| console.log(`Loaded ${tools.length} tools`); | ||
|
|
||
| const tool = tools.getTool('hris_list_employees'); | ||
| if (!tool) { | ||
| throw new Error('Tool hris_list_employees not found in the catalog'); | ||
| } | ||
|
|
||
| const result = await tool.execute({ | ||
| query: { limit: 5 }, | ||
| }); | ||
| console.log('Sample execution result:', JSON.stringify(result, null, 2)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { Client } from '@modelcontextprotocol/sdk/client/index.js'; | ||
| import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'; | ||
| import { version } from '../package.json'; | ||
|
|
||
| interface MCPClientOptions { | ||
| baseUrl: string; | ||
| headers?: Record<string, string>; | ||
| } | ||
|
|
||
| interface MCPClient { | ||
| /** underlying MCP client */ | ||
| client: Client; | ||
|
|
||
| /** underlying transport */ | ||
| transport: StreamableHTTPClientTransport; | ||
|
|
||
| /** cleanup client and transport */ | ||
| [Symbol.asyncDispose](): Promise<void>; | ||
| } | ||
|
|
||
| /** | ||
| * Create a Model Context Protocol (MCP) client. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { createMCPClient } from '@stackone/ai'; | ||
| * | ||
| * await using clients = await createMCPClient({ | ||
| * baseUrl: 'https://api.modelcontextprotocol.org', | ||
| * headers: { | ||
| * 'Authorization': 'Bearer YOUR_API_KEY', | ||
| * }, | ||
| * }); | ||
| * ``` | ||
| */ | ||
| export async function createMCPClient({ baseUrl, headers }: MCPClientOptions): Promise<MCPClient> { | ||
| const transport = new StreamableHTTPClientTransport(new URL(baseUrl), { | ||
| requestInit: { | ||
| headers, | ||
| }, | ||
| }); | ||
|
|
||
| const client = new Client({ | ||
| name: 'StackOne AI SDK', | ||
| version, | ||
| }); | ||
|
|
||
| return { | ||
| client, | ||
| transport, | ||
| async [Symbol.asyncDispose]() { | ||
| await Promise.all([client.close(), transport.close()]); | ||
| }, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
close mcp client with
await using