Skip to content

Conversation

@karpetrosyan
Copy link
Contributor

@karpetrosyan karpetrosyan commented Jan 13, 2026

Add context parameter to tool run functions

Adds an optional meta parameter to tool run functions that provides access to tool invocation metadata.

Usage

const tool = betaTool({
  name: 'calculator',
  input_schema: { /* ... */ },
  description: 'Perform arithmetic',
  run: (input, meta) => {
    console.log(`Tool invocation ID: ${meta?.toolUseBlock.id}`);
    return String(input.a + input.b);
  },
});

sd-st and others added 18 commits November 18, 2025 15:51
fix(client): don't strip path from filename for skills endpoint
docs: update README with Claude branding

- Add Claude sparkle logo to header
- Rename to "Claude SDK for TypeScript"
- Use "Claude API" terminology instead of "Anthropic API"
- Link to TypeScript SDK docs at platform.claude.com
- Simplify and consolidate documentation sections

Co-Authored-By: Claude <[email protected]>
* "Claude PR Assistant workflow"

* "Claude Code Review workflow"
@karpetrosyan karpetrosyan requested a review from a team as a code owner January 13, 2026 07:05
@felixfbecker
Copy link
Contributor

Thank you for the PR! Could you share the background/motivation/use case for this change?

@karpetrosyan karpetrosyan changed the base branch from main to next January 13, 2026 07:45
@karpetrosyan karpetrosyan force-pushed the add-context-to-tools branch 2 times, most recently from 294d05a to 930d26b Compare January 13, 2026 18:06
@karpetrosyan
Copy link
Contributor Author

@RobertCraigie would you be able to take a look?

dtmeadows and others added 2 commits January 26, 2026 09:09
* feat(api): update via SDK Studio

* feat(api): update via SDK Studio

* codegen metadata

* feat: migrate output_format to output_config.format for structured outputs

- Update beta header from structured-outputs-2025-11-13 to structured-outputs-2025-12-15
- Transform deprecated output_format parameter to output_config.format
- Add warning when both output_format and output_config.format are provided
- Update beta-parser to support parsing from either location
- Update tests to expect new output_config.format structure

Co-Authored-By: Claude Code (/Users/davidmeadows/stainless/stainless) <[email protected]>

* feat: add @deprecated JSDoc tag and update example to use output_config

- Add @deprecated JSDoc tag to output_format parameter in BetaParseableMessageCreateParams
- Update parsing-zod.ts example to use output_config.format instead of output_format

Co-Authored-By: Claude Code (/Users/davidmeadows/stainless/stainless/dist/customer-repos/stainless-sdks/anthropic-typescript) <[email protected]>

* fix: throw error instead of warning when both output params provided

Co-Authored-By: Claude Code (/Users/davidmeadows/stainless/stainless/dist/customer-repos/stainless-sdks/anthropic-typescript) <[email protected]>

* Remove note about beta header injection

* clean up things a bit

* revert changes

* undo a change

* undo changes from next

* fixup!

* fixes

* fixup!

* fix: move structured output formatting to dedicated function and add to token counting

* feat: Test exception case in structured output

* feat: improve types and add other unit test for structured output transformation

---------

Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
Co-authored-by: Claude Code (/Users/davidmeadows/stainless/stainless) <[email protected]>
Co-authored-by: Cameron McAteer <[email protected]>
Add helper functions for integrating with the [Model Context Protocol
(MCP) SDK](https://github.com/modelcontextprotocol/sdk). These helpers
reduce the boilerplate required to convert MCP types to Anthropic API
types from ~100+ lines to single function calls.

**New helpers:**
- `mcpTool(tool, mcpClient)` - Convert single MCP tool to
`BetaRunnableTool`
- `mcpTools(tools, mcpClient)` - Convert array of MCP tools to
`BetaRunnableTool[]` for use with `toolRunner()`
- `mcpMessage(message)` - Convert single MCP `PromptMessage` to
`BetaMessageParam`
- `mcpMessages(messages)` - Convert array of MCP `PromptMessage` to
`BetaMessageParam[]`
- `mcpContent(content)` - Convert single MCP content block to Anthropic
content block
- `mcpResourceToContent(resource)` - Convert MCP resource to content
block (document or image)
- `mcpResourceToFile(resource)` - Convert MCP resource to `File` for
`files.upload()`
Copy link
Contributor

@felixfbecker felixfbecker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition looks nice but would still be good to understand the motivation/use case. Could you add a PR description?

run: (args: NoInfer<FromSchema<Schema>>) => Promisable<string | Array<BetaToolResultContentBlockParam>>;
run: (
args: NoInfer<FromSchema<Schema>>,
context?: BetaToolRunContext,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since "context" is a defined term in the context of LLMs, a different name might be better, e.g. meta

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed it to meta

@karpetrosyan
Copy link
Contributor Author

The addition looks nice but would still be good to understand the motivation/use case. Could you add a PR description?

@felixfbecker It adds metadata to tool runners so they can do some logging/tracing. I’m also preparing an update so we provide an abort signal as well, so tools can be aborted.
I’ve also added a minimal description to the PR.

@stainless-app stainless-app bot force-pushed the next branch 2 times, most recently from eeb7fab to 7b4849b Compare January 29, 2026 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants