PowerShell SDK for building and consuming Model Context Protocol servers and clients, targeting specification revision 2026-07-28 with dual-era support for 2025-11-25 and 2025-06-18.
Status: milestone M5 (dual era). Servers expose PowerShell functions, cmdlets, scripts and script blocks as tools, resources (fixed content, files, directories, handlers, RFC 6570 templates) and prompts, with argument completion and caching hints, over stdio and Streamable HTTP with the stateless 2026-07-28 lifecycle (
server/discover, per-request_meta, request metadata headers, progress, cancellation, log notifications). Handlers ask the user for input (elicitation) or the client for sampling and roots through multi-round-trip requests with a signedrequestState; clients subscribe to list changes and resource updates withsubscriptions/listen, and tools, resources and prompts can be registered while the server runs. The client side consumes all of it over both transports and caches results for thettlMsthe server sends. Both sides also speak theinitializehandshake of 2025-11-25 and 2025-06-18: a server serves both eras on the same process and endpoint (legacy sessions withMcp-Session-Id, GET stream, DELETE, server-initiated elicitation, sampling and roots requests), a client detects the era of the server and falls back to the handshake. The official conformance suite runs in CI for both requirement sets: every server scenario of 2026-07-28 and 2025-11-25 passes, and on the client side everything but authorization, which is listed in conformance-baseline.yml and follows in M6. The milestones are in ROADMAP.md; the design is in docs/implementation-plan.md.
- PowerShell 7.4 or later on Windows, Linux or macOS (7.4 LTS, 7.5 and 7.6 LTS are tested in CI).
CompatiblePSEditions = Core; Windows PowerShell 5.1 is not supported and refuses to import the module.- No runtime dependencies: a pure script module that only uses assemblies shipped with PowerShell.
A server is a script that registers tools and serves stdio:
#Requires -Version 7.4
Import-Module ModelContextProtocol
function Get-Weather {
<#
.SYNOPSIS
Current weather for a location.
.PARAMETER Location
City or postal code.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory)] [string] $Location,
[ValidateSet('metric', 'imperial')] [string] $Units = 'metric'
)
[pscustomobject]@{ location = $Location; temperature = 21.5; units = $Units }
}
New-McpServer -Name weather -Version 1.0.0 -Instructions 'Weather lookups.' -SetDefault
Register-McpTool -Command (Get-Command Get-Weather) # schema from the parameters and the help
Register-McpTool -Name echo -ScriptBlock { param([Parameter(Mandatory)][string] $Text) $Text }
Start-McpServer # serves stdio until stdin closesHosts start it with pwsh -NoLogo -NoProfile -NonInteractive -File ./weather-server.ps1. Tool arguments are
validated against the generated JSON Schema and bound to the parameters; objects become
structuredContent, strings become text, New-McpContent builds image, audio and resource blocks, and
Write-McpProgress/Write-McpLog reach the client through a Context parameter. Handlers run in a worker
runspace pool, so nothing they write to the host can reach stdout.
Resources and prompts are registered the same way; resource templates bind their variables to parameters,
prompt arguments come from the param() block, and a ValidateSet doubles as argument completion:
Register-McpResource -Uri 'weather://stations' -MimeType application/json -Content '["Berlin","Vienna"]'
Register-McpResource -UriTemplate 'weather://{city}/current' -ScriptBlock { param($city) Get-Weather -Location $city } -TtlMs 10000
Register-McpResource -Path ./docs -Uri 'docs://' # every file below ./docs, as docs://{+path}
Register-McpPrompt -Name 'weather-report' -Description 'Asks for a weather report.' -ScriptBlock {
param([Parameter(Mandatory)] [ValidateSet('Berlin', 'Vienna')] [string] $City)
"Write a three-sentence weather report for $City."
}The client side:
$session = Connect-McpServer -Command pwsh -Arguments '-NoLogo', '-NoProfile', '-NonInteractive', '-File', './weather-server.ps1'
Get-McpServerInfo | Format-List
Get-McpTool | Select-Object Name, Description
$result = Invoke-McpTool -Name Get-Weather -Arguments @{ Location = 'Berlin' }
$result.StructuredContent.temperature
Get-McpResource | Read-McpResource # cached for the ttlMs of each result
(Invoke-McpPrompt -Name weather-report -Arguments @{ City = 'Vienna' }).Messages
(Get-McpCompletion -PromptName weather-report -Argument City -Value 'Vi').Values
Disconnect-McpServerA handler that needs input asks for it; the client answers through a callback, and the request is retried with the answer (see docs/concepts/mrtr.md):
Register-McpTool -Name 'delete-files' -ScriptBlock {
param([Parameter(Mandatory)] [string] $Pattern, $Context)
$answer = Request-McpElicitation -Context $Context -Key 'confirm' -Message "Delete '$Pattern'?" -Schema @{ ok = @{ type = 'boolean' } } -Required ok
if ($answer.Action -ne 'accept' -or -not $answer.Content.ok) { return 'Cancelled.' }
Remove-Item -Path $Pattern
}
$session = Connect-McpServer -Command pwsh -Arguments '-File', './server.ps1' -OnElicitation { param($Request) @{ ok = $true } }
$subscription = Register-McpSubscription -ToolsListChanged -ResourceUri 'weather://stations'
Receive-McpNotification -Subscription $subscription -TimeoutSeconds 30Over Streamable HTTP the same server listens on a URL, and the same client commands connect to it:
Start-McpServer -Transport Http -Url http://127.0.0.1:8080/mcp/ # POST-only endpoint, SSE for progress
$session = Connect-McpServer -Url http://127.0.0.1:8080/mcp/
Invoke-McpTool -Name Get-Weather -Arguments @{ Location = 'Berlin' }The HTTP server validates the request metadata headers of revision 2026-07-28 (MCP-Protocol-Version,
Mcp-Method, Mcp-Name, Mcp-Param-*), the Host and Origin headers (DNS rebinding protection) and answers with the
HTTP statuses the specification assigns to the JSON-RPC error codes; the client sends those headers,
mirrors parameters registered with Register-McpTool -Header into Mcp-Param-* headers and reads JSON or
SSE responses. See docs/concepts/transports.md.
Connect-McpServer -Server $serverObject runs a server in a background runspace over an in-memory transport,
which is how the tests exercise servers without child processes. Invoke-McpToolHandler calls a registered
tool directly for unit tests of the tool itself. See examples/echo-server.ps1, examples/weather-server.ps1
(all server primitives), examples/elicitation-server.ps1 (input requests), examples/http-server.ps1,
docs/concepts/server-primitives.md and
docs/development.md for the Inspector command line.
git clone https://github.com/nullthrone/powershell-sdk.git
cd powershell-sdk
./build.ps1 -Bootstrap # installs Pester, PSScriptAnalyzer, ModuleBuilder (+ Configuration, Metadata), InvokeBuild, PlatyPS
./build.ps1 -Task CI # Analyze, Test, Package, PublishLocal
Import-Module ./output/ModelContextProtocol/0.1.0/ModelContextProtocol.psd1CONTRIBUTING.md describes the development workflow, the repository layout and the coding conventions; docs/development.md has the details of the build and test tooling.
- Pure PowerShell. One script module assembled from
src/with ModuleBuilder; engine classes are internal and exported through type accelerators, the public API consists of functions with the noun prefixMcp. - Stateless 2026-07-28 core, isolated legacy layer.
server/discover, per-request_meta, MRTR input requests andsubscriptions/listenin the core;initialize-based sessions of 2025-11-25 / 2025-06-18 in a separate legacy component that shares the same endpoint and process. - Transports. stdio (raw UTF-8 streams, nothing but protocol messages on stdout) and Streamable HTTP on
System.Net.HttpListenerwith an SSE writer; an in-memory transport for tests. - Conformance first. The official conformance suite runs in CI (
.github/workflows/conformance.yml,./build.ps1 -Task Conformance) against a baseline that may only shrink; 1.0.0 requires an empty baseline for the 2026-07-28 and 2025-11-25 requirement sets.
| Path | Purpose |
|---|---|
src/ |
Module sources and manifest |
tests/ |
Pester tests (unit, integration, spec, compat) and the conformance fixtures (tests/Conformance) |
tools/ |
Custom PSScriptAnalyzer rules, maintenance scripts, offline package drop folder |
docs/ |
Concept documentation, implementation plan, research material |
.github/ |
CI matrix, release workflow, label sync, issue templates |
Governance: ROADMAP.md, DEPENDENCY_POLICY.md, SECURITY.md, CODE_OF_CONDUCT.md, CHANGELOG.md.
License: MIT.