MCPcopy Create free account
hub / github.com/WebMCP-org/chrome-devtools-quickstart / setupCounter

Function setupCounter

counter.js:1–55  ·  view source on GitHub ↗
(element)

Source from the content-addressed store, hash-verified

1export function setupCounter(element) {
2 let counter = 0
3 const setCounter = (count) => {
4 counter = count
5 element.innerHTML = `count is ${counter}`
6 }
7 element.addEventListener('click', () => setCounter(counter + 1))
8 setCounter(0)
9
10 const registration = navigator.modelContext.registerTool({
11 name: "get_page_title",
12 description: "Get current page title",
13 inputSchema: { type: "object", properties: {} },
14 async execute() {
15 return {
16 content: [{ type: "text", text: document.title }]
17 };
18 }
19});
20
21navigator.modelContext.registerTool({
22 name: 'get_counter',
23 description: 'This will return the current value of the counter, call this before setting the counter',
24 inputSchema: {
25 type: 'object',
26 properties: {}
27 },
28 async execute(args) {
29 return {
30 content:
31 [{type: 'text', text: `the current counter value is ${counter}`}]
32 }
33 }
34});
35
36navigator.modelContext.registerTool({
37 name: 'set_counter',
38 description: 'This will set the counter to the desired value',
39 inputSchema: {
40 type: 'object',
41 properties: {
42 newCounterValue: { type: 'number', description: 'The number you want to set the counter to' }
43 },
44 required: ['newCounterValue']
45 },
46 async execute(args) {
47 const newValue = args.newCounterValue
48 setCounter(newValue)
49 return {
50 content: [{ type: 'text', text: 'counter is now ' + args.newCounterValue }]
51 };
52 }
53})
54
55}

Callers 1

main.jsFile · 0.90

Calls 1

setCounterFunction · 0.85

Tested by

no test coverage detected