Skip to main content

Chapter 16: Building Packs in Other Languages

Worka v2 supports multiple language SDKs. Each SDK provides:

  • A typed MCP tool interface
  • A2UI builders
  • In‑process transport inside the WASM runtime

This means you do not run external HTTP servers. Tools are invoked directly by the host inside the pack sandbox.

If you choose a non‑Rust SDK, use the same structure as the Rust pack:

my-pack/
├── aip.json
├── src/
└── assets/ locales/ sql/

Each SDK provides its own build tooling to compile to WASM. Refer to the SDK documentation for your language of choice. const toolArgs = params.arguments;

// ... (we will add routing logic next) });


### Step 4: Implementing and Routing Tools

It\'s good practice to define your tool logic in separate functions and then use a map or a `switch` statement to call the correct one.

Let\'s implement our `greet` tool and a simple router.

```javascript
// Define the logic for the greet tool
const greet = (params) => {
if (!params || !params.name) {
// It\'s good practice to validate your parameters
throw new Error('Missing \'name\' parameter');
}
return { greeting: `Hello, ${params.name}!` };
};

// Create a map to hold all your tool handlers
const toolHandlers = {
greet: greet,
// another_tool: anotherToolFunction,
};

// Inside your app.post('/', ...) handler:
const handler = toolHandlers[toolName];

if (handler) {
try {
const result = handler(toolArgs);
// Send a successful response
res.json({ jsonrpc: '2.0', result });
} catch (e) {
// Send an error response if the tool logic throws an error
res.status(400).json({
jsonrpc: '2.0',
error: { code: -32602, message: e.message }
});
}
} else {
// Handle the case where the tool name doesn't exist
res.status(404).json({
jsonrpc: '2.0',
error: { code: -32601, message: 'Tool not found' }
});
}

This structure makes it easy to add new tools. Simply write a new function and add it to the toolHandlers object. The worka dev process will automatically restart your Node.js server when you save your changes, giving you the same hot-reloading experience as with Rust servers.