Skip to content

Commit 25a9a6b

Browse files
committed
feat(server): allow textDetail/cssLevel request parameters and prune responses
1 parent 8c70382 commit 25a9a6b

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

packages/server/src/services/mcp-service.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import {
55
ListToolsRequestSchema,
66
} from '@modelcontextprotocol/sdk/types.js';
77
import { version } from 'process';
8+
import { CSS_DETAIL_OPTIONS, TEXT_DETAIL_OPTIONS } from '@mcp-pointer/shared/detail';
89
import SharedStateService from './shared-state-service';
10+
import {
11+
normalizeDetailParameters,
12+
shapeElementForDetail,
13+
type DetailParameters,
14+
type NormalizedDetailParameters,
15+
} from '../utils/element-detail';
916

1017
enum MCPToolName {
1118
GET_POINTED_ELEMENT = 'get-pointed-element',
@@ -47,10 +54,21 @@ export default class MCPService {
4754
tools: [
4855
{
4956
name: MCPToolName.GET_POINTED_ELEMENT,
50-
description: 'Get information about the currently pointed/shown DOM element from the browser extension, in order to let you see a specific element the user is showing you on his/her the browser.',
57+
description: 'Get information about the currently pointed/shown DOM element. Control returned payload size with optional textDetail (full|visible|none) and cssLevel (0-3).',
5158
inputSchema: {
5259
type: 'object',
53-
properties: {},
60+
properties: {
61+
textDetail: {
62+
type: 'string',
63+
enum: [...TEXT_DETAIL_OPTIONS],
64+
description: 'Controls how much text is returned. full (default) includes hidden text fallback, visible uses only rendered text, none omits text fields.',
65+
},
66+
cssLevel: {
67+
type: 'integer',
68+
enum: [...CSS_DETAIL_OPTIONS],
69+
description: 'Controls CSS payload detail. 0 omits CSS, 1 includes layout basics, 2 adds box model, 3 returns the full computed style.',
70+
},
71+
},
5472
required: [],
5573
},
5674
},
@@ -60,13 +78,16 @@ export default class MCPService {
6078

6179
private async handleCallTool(request: any) {
6280
if (request.params.name === MCPToolName.GET_POINTED_ELEMENT) {
63-
return this.getTargetedElement();
81+
const normalized = normalizeDetailParameters(
82+
request.params.arguments as DetailParameters | undefined,
83+
);
84+
return this.getTargetedElement(normalized);
6485
}
6586

6687
throw new Error(`Unknown tool: ${request.params.name}`);
6788
}
6889

69-
private async getTargetedElement() {
90+
private async getTargetedElement(details: NormalizedDetailParameters) {
7091
const element = await this.sharedState.getCurrentElement();
7192

7293
if (!element) {
@@ -81,11 +102,13 @@ export default class MCPService {
81102
};
82103
}
83104

105+
const shapedElement = shapeElementForDetail(element, details.textDetail, details.cssLevel);
106+
84107
return {
85108
content: [
86109
{
87110
type: 'text',
88-
text: JSON.stringify(element, null, 2),
111+
text: JSON.stringify(shapedElement, null, 2),
89112
},
90113
],
91114
};

0 commit comments

Comments
 (0)