pi-anthropic-oauth 0.2.1 → 0.2.2

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/convert.ts +18 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-anthropic-oauth",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Claude Pro/Max OAuth extension for Pi",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/convert.ts CHANGED
@@ -42,11 +42,28 @@ const claudeCodeTools = [
42
42
  ] as const;
43
43
  const claudeCodeToolLookup = new Map(claudeCodeTools.map((name) => [name.toLowerCase(), name]));
44
44
 
45
+ // Anthropic's OAuth classifier rejects tool definitions with names outside
46
+ // Claude Code's own tool set with a 400 "Third-party apps now draw from your
47
+ // extra usage" error. Claude Code exposes MCP tools as `mcp__<server>__<tool>`,
48
+ // so unknown tools are namespaced under `mcp__pi__`.
49
+ const CLAUDE_CODE_MCP_TOOL_PREFIX = "mcp__pi__";
50
+
51
+ function sanitizeCustomToolName(name: string): string {
52
+ return name.replace(/[^a-zA-Z0-9_-]/g, "_");
53
+ }
54
+
45
55
  export function toClaudeCodeToolName(name: string): string {
46
- return claudeCodeToolLookup.get(name.toLowerCase()) ?? name;
56
+ return (
57
+ claudeCodeToolLookup.get(name.toLowerCase()) ??
58
+ `${CLAUDE_CODE_MCP_TOOL_PREFIX}${sanitizeCustomToolName(name)}`
59
+ );
47
60
  }
48
61
 
49
62
  export function fromClaudeCodeToolName(name: string, tools?: Tool[]): string {
63
+ if (name.startsWith(CLAUDE_CODE_MCP_TOOL_PREFIX)) {
64
+ const stripped = name.slice(CLAUDE_CODE_MCP_TOOL_PREFIX.length);
65
+ return tools?.find((tool) => sanitizeCustomToolName(tool.name) === stripped)?.name ?? stripped;
66
+ }
50
67
  const lower = name.toLowerCase();
51
68
  return tools?.find((tool) => tool.name.toLowerCase() === lower)?.name ?? name;
52
69
  }