Skip to content

Commit 5fccba7

Browse files
committed
Strip bloated plan.features from wpcom_request responses
The WP.com /sites/{id} endpoint returns a plan object whose features sub-field alone is 60K+ characters, pushing the total response past Claude Code's ~100K character MCP tool result limit. The agent only needs product_slug, is_free, and expired to gate features, since the system prompt hardcodes what each plan tier can and can't do. Strip plan.features and keep only essential plan properties.
1 parent a2cb85f commit 5fccba7

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

apps/cli/ai/wpcom-tools.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,32 @@ import wpcomFactory from '@studio/common/lib/wpcom-factory';
33
import wpcomXhrRequest from '@studio/common/lib/wpcom-xhr-request-factory';
44
import { z } from 'zod/v4';
55

6+
/**
7+
* Strips known bloated fields from API responses to stay within MCP tool result
8+
* size limits (~100k characters). The WP.com /sites/{id} endpoint returns a plan
9+
* object whose `features` sub-field alone can be 60K+ characters. The agent only
10+
* needs a few plan properties (product_slug, is_free, expired) to gate features,
11+
* since the system prompt hardcodes what each plan tier can and can't do.
12+
*/
13+
function compactResponse( result: ApiResponse ): ApiResponse {
14+
if ( result && typeof result === 'object' && ! Array.isArray( result ) ) {
15+
// plan.features can be 60K+ chars — keep only essential plan properties
16+
if ( result.plan && typeof result.plan === 'object' && result.plan.features ) {
17+
result = {
18+
...result,
19+
plan: {
20+
product_id: result.plan.product_id,
21+
product_slug: result.plan.product_slug,
22+
product_name_short: result.plan.product_name_short,
23+
expired: result.plan.expired,
24+
is_free: result.plan.is_free,
25+
},
26+
};
27+
}
28+
}
29+
return result;
30+
}
31+
632
function errorResult( message: string ) {
733
return {
834
content: [ { type: 'text' as const, text: message } ],
@@ -106,7 +132,8 @@ export function createWpcomToolDefinitions( token: string, siteId: number ) {
106132
break;
107133
}
108134

109-
return textResult( JSON.stringify( result, null, 2 ) );
135+
const compacted = compactResponse( result );
136+
return textResult( JSON.stringify( compacted, null, 2 ) );
110137
} catch ( error ) {
111138
return errorResult(
112139
`WP.com API request failed (${ args.method } ${ args.path }): ${ getErrorMessage(

0 commit comments

Comments
 (0)