Skip to content

Add Learn MCP Server tool-calling sample#642

Open
pdebruin wants to merge 3 commits intomicrosoft:mainfrom
pdebruin:pdebruin/learn-mcp-tool-calling
Open

Add Learn MCP Server tool-calling sample#642
pdebruin wants to merge 3 commits intomicrosoft:mainfrom
pdebruin:pdebruin/learn-mcp-tool-calling

Conversation

@pdebruin
Copy link
Copy Markdown

@pdebruin pdebruin commented Apr 16, 2026

Adds JS and C# samples that use Foundry Local with the Learn MCP Server to create a doc-grounded Q&A assistant.

The model calls a search_docs tool that queries learn.microsoft.com via MCP (JSON-RPC over HTTP), then synthesizes answers from official Microsoft documentation. All inference runs locally on-device.

JS sample (samples/js/learn-mcp-tool-calling/):

  • app.js, package.json
  • Tested and working end-to-end

C# sample (samples/cs/learn-mcp-tool-calling/):

README updates:

  • samples/README.md — updated JS count (12 → 13) and C# count (12 → 13)
  • samples/js/README.md — added table entry
  • samples/cs/README.md — added table entry

Adds a JS sample that uses Foundry Local with the Learn MCP Server
to create a doc-grounded Q&A assistant. The model calls a search_docs
tool that queries learn.microsoft.com via MCP (JSON-RPC over HTTP),
then synthesizes answers from official Microsoft documentation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 16, 2026 11:00
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 16, 2026

@pdebruin is attempting to deploy a commit to the MSFT-AIP Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new JavaScript sample demonstrating tool-calling with Foundry Local, grounded by Microsoft Learn documentation retrieved via the Learn MCP Server (JSON-RPC over HTTP).

Changes:

  • Adds a new JS sample (samples/js/learn-mcp-tool-calling/) with an interactive CLI assistant that calls a search_docs tool backed by Learn MCP Server.
  • Updates the JS samples index to include the new sample.
  • Updates the top-level samples README to reflect the new JS sample count (13).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
samples/js/learn-mcp-tool-calling/package.json Adds a runnable Node.js sample package using foundry-local-sdk (+ WinML optional dep).
samples/js/learn-mcp-tool-calling/app.js Implements the CLI assistant, MCP-backed search_docs tool, and a tool-calling loop.
samples/js/README.md Adds the new sample to the JS samples table.
samples/README.md Updates JavaScript sample count from 12 to 13 and mentions Learn MCP Server.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


for (const toolCall of choice.tool_calls) {
const functionName = toolCall.function.name;
const args = JSON.parse(toolCall.function.arguments);
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON.parse(toolCall.function.arguments) can throw (missing/empty/invalid JSON) and will crash the sample mid-conversation. Consider a safe parse with a default (e.g., {}) and on parse failure push a role:'tool' error result for that tool_call_id instead of throwing, so the loop can continue gracefully.

Suggested change
const args = JSON.parse(toolCall.function.arguments);
const rawArguments = typeof toolCall.function.arguments === 'string' && toolCall.function.arguments.trim() !== ''
? toolCall.function.arguments
: '{}';
let args;
try {
args = JSON.parse(rawArguments);
} catch (error) {
messages.push({
role: 'tool',
tool_call_id: toolCall.id,
content: JSON.stringify({
error: `Invalid tool arguments for ${functionName}: ${error.message}`
})
});
continue;
}

Copilot uses AI. Check for mistakes.
pdebruin and others added 2 commits April 16, 2026 14:10
Adds a C# sample that uses Foundry Local with the Learn MCP Server
to create a doc-grounded Q&A assistant. Adapted from tutorial-tool-calling
with search_docs tool calling learn.microsoft.com via MCP (JSON-RPC).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds a C# sample (learn-mcp-tool-calling) that uses Foundry Local with
the Learn MCP Server for doc-grounded Q&A. Hardened FormatSearchResults
with TryGetProperty throughout and added ValueKind guards to prevent
exceptions on unexpected MCP response shapes.

Note: all C# tool-calling samples currently crash at runtime due to a
Betalgo.Ranul.OpenAI version mismatch in the SDK (microsoft#632). The sample
code is correct and will work once the SDK is updated.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants