Triggers: codeful MCP tool, MCP server tool, generate runTool, MCP tool JavaScript,
Dataverse MCP tool, server logic for MCP App
Keywords: mcp apps, codeful tool, runTool, dataApi, Dataverse, server runtime
Aliases: /generate-codeful-mcp-tool, /codeful-tool
References:
You generate a matched pair of files for one MCP tool:
<tool-name>.tool.js: the complete JavaScript server implementation.<tool-name>.tool.json: declarative registration metadata containing the tool name,description, input schema, output schema, and MCP tool annotations.
The host imports the JavaScript module and calls:
await runTool({ toolInput, dataApi });
Before generating, establish:
model-actionable tool description; ask only when the intended behavior is ambiguous.
representative input object, or an exact field description. Never guess the input shape.
whether any write creates, appends, updates, overwrites, or deletes state.
Ask only for information that is missing. A sample input/output is preferred but not
mandatory when the user has supplied an equally precise contract.
Read:
${PLUGIN_ROOT}/references/codeful-tool-host-data-api.d.ts
${PLUGIN_ROOT}/samples/account-summary.tool.js
${PLUGIN_ROOT}/samples/account-summary.tool.json
The generated runtime is plain ESM JavaScript, and the sidecar is plain JSON. Type files
are generation-time references only and MUST NOT be imported by the output.
Skip this phase when the tool does not use Dataverse.
For a Dataverse-backed tool:
```powershell
pac model list-tables --search "table terms"
```
--search is substring-based. Post-filter its output and accept a table only when its
logical name exactly matches the selected result. If multiple tables remain plausible,
ask the user to choose.
```powershell
pac model genpage generate-types --data-sources "logical1,logical2" --output-file "
```
RuntimeTypes.ts. Extract the registered tables, exact readable/writable logicalcolumns, lookup shapes, choice names, and raw numeric choice values.
not derive them from display names.
If discovery or type generation fails, stop and report the error. Do not fall back to
invented tables or columns. Delete the temporary types and directory after validation so
the final output contains only the requested .tool.js, .tool.json, and optional
widget files.
Write <tool-name>.tool.js and <tool-name>.tool.json in the user's working directory
unless they requested another output directory. Both files MUST use the same basename,
which MUST equal the confirmed kebab-case tool name.
The JavaScript file MUST:
runTool, preferably:```javascript
export async function runTool({ toolInput, dataApi }) {
// complete implementation
}
```
filesystem access, environment-variable access, or generated-type dependency.
toolInput before using it. Apply bounds to counts andescape values interpolated into OData filters.
select,filter, orderBy, and row objects.
"<column>@OData.Community.Display.V1.FormattedValue".
page.rows. Follow page.loadMoreRows() only whilepage.hasMoreRows is true and the function exists.
_<field>_value shape from RuntimeTypes.ts; neveremit raw Web API @odata.bind keys.
dataApi failures throw. Catch only when adding useful context, and rethrow with theoriginal error as the cause. Never return a success-shaped fallback after a failed read
or write.
loadMoreRows, functions, classinstances, or cyclic objects.
row contents, identifiers, or other user data in telemetry properties.
The JSON sidecar MUST be valid JSON with exactly these top-level fields:
{
"name": "account-summary",
"description": "Search accounts and return revenue and status summaries.",
"annotations": {
"readOnlyHint": true,
"destructiveHint": false,
"idempotentHint": true,
"openWorldHint": false
},
"inputSchema": {
"type": "object",
"properties": {}
},
"outputSchema": {
"type": "object",
"properties": {}
}
}
name: exactly the confirmed tool name and the shared file basename.description: concise, model-actionable guidance explaining what the tool does and whento call it. Do not copy the user's prompt verbatim or include implementation details.
annotations: MCPToolAnnotations
describing the tool's behavior. Always emit all four boolean hints:
readOnlyHint: true only when the tool cannot modify Dataverse or any other state.destructiveHint: true when the tool may delete, overwrite, or otherwise cause adestructive update. Set it to false for read-only tools and non-destructive creates
or additive writes.
idempotentHint: true when repeated calls with the same valid input have noadditional effect. Reads, deterministic calculations, and updates that set the same
values are idempotent; creates and append-style operations are not.
openWorldHint: always false because the codeful runtime cannot access arbitraryexternal systems.
Infer these values from the generated implementation and requested behavior. If the
write semantics are genuinely ambiguous, ask before generating rather than guessing.
Treat annotations as advisory metadata, not as a substitute for runtime validation or
authorization.
inputSchema: the complete JSON Schema for toolInput. Use an object root, list everyaccepted field under properties, identify required fields with required, encode
runtime constraints such as bounds, formats, enums, and array item shapes, and setadditionalProperties: false unless the user explicitly requires extensible input.
outputSchema: the JSON Schema for the model-visible structuredContent businesspayload. For a plain-object return, describe the complete returned object because the
host promotes it to structuredContent. For an envelope return, describe only itsstructuredContent property. Never include content, authored meta, or runtime_meta in outputSchema.
Use standard JSON Schema keywords only. Do not include credentials, environment
identifiers, Dataverse discovery artifacts, host configuration, JavaScript expressions,
comments, or placeholders in the sidecar.
Choose the smallest correct result shape.
Return a plain object when all useful output belongs in model-visible structured data:
return { records, totalCount: records.length };
The host promotes that object to MCP structuredContent.
Return an envelope when the channels have different audiences:
return {
content: `Found ${records.length} records.`,
structuredContent: { records },
meta: { preferredView: "table" },
};
content: model-visible conversational text, either a string or text content blocks.structuredContent: model-visible machine-readable object.meta: widget-only object. The host maps it to MCP _meta; widgets read result._meta.The names content, structuredContent, and meta are reserved envelope keys. If a
business payload naturally has any of those keys, wrap the whole payload explicitly:
return { structuredContent: businessPayload };
Do not mix envelope keys with unrelated top-level business fields.
Before reporting completion:
.tool.js and one matching .tool.json were created forthis skill.
runTool is a function.Importing MUST NOT execute data access or other top-level side effects.
JSON.parse. Confirm it has exactly name, description,annotations, inputSchema, and outputSchema; the name matches both filenames;
all four annotation hints are booleans, openWorldHint is false, the other hints
match the implementation's actual behavior, both schemas have object roots, and every
input constraint enforced by the runtime is represented in inputSchema.
require, placeholders, guessed columns, and unsupportedhost access.
runTool with an in-memory mockdataApi from an inline Node script. Do not create a persistent test file.
functions or non-serializable values, and its structured payload conforms tooutputSchema. Confirm the representative input conforms to inputSchema.
When the user asks for a widget:
.tool.js and .tool.json first.structuredContent.content, structuredContent, and _meta (renamed from theauthored meta field).
generate-mcp-app-ui with the visual requirements, tool name, input sample, andrepresentative full result. Forward an explicit CDN policy from the user's request.
If none was supplied, let the UI skill ask its required CDN-policy question; do not
assume public URLs are allowed.
.tool.js, one .tool.json, and one single-file.html using the selected CDN policy.
When editing an existing codeful tool, read both paired files and change only the
requested behavior. Keep runtime validation and metadata schemas synchronized. Re-run
schema verification if the edit introduces a table, column, lookup, or choice value not
already verified for the file.
State both generated tool file paths and summarize the description, tool annotations,
input contract, and structured result contract. If a widget was requested, also state the
HTML path and which result channels it consumes.