Skip to content
Simon Place
FR EN
Book a Meet call

Module 3 of 10, lesson 4 of 5

Practice

Tools and MCP

Write the code

Runs in your browser, with no install, account or API key. The model is scripted, so the results are repeatable.

// registry: { name: { schema, run } }async function execute(block, registry) {  const tool = registry[block.name];  const output = await tool.run(block.input);  return { type: 'tool_result', tool_use_id: block.id, content: JSON.stringify(output) };}module.exports = { execute };
Repair the agentHarden the tool dispatcher
Open in the editor
function makeRefundTool(pay) {  return async function refund({ key, order, amount }) {    const receipt = await pay({ order, amount });    return { status: 'refunded', receipt };  };}module.exports = { makeRefundTool };
Give the agent a skillMake refunds idempotent
Open in the editor
// tools: { name: { description, inputSchema, run } }async function handle(request, tools) {  // TODO: tools/list, tools/call, errors, notifications  return null;}module.exports = { handle };
Give the agent a skillWrite a small MCP handler
Open in the editor

Running project

Running project: define three tools for the refund agent: read an order, check the policy, issue a refund. Write their JSON schemas and three useful error messages. Work out which one must be idempotent, and how.

Practice

Some of these need a free account or an API key, which may be paid.

Legal notice and privacy