{"id":26410726,"url":"https://github.com/chadnpc/mcp","last_synced_at":"2025-08-14T12:37:41.542Z","repository":{"id":282588638,"uuid":"949063637","full_name":"chadnpc/MCP","owner":"chadnpc","description":"Provides core framework for building MCP-compliant AI agents and tools in PowerShell.","archived":false,"fork":false,"pushed_at":"2025-03-31T20:07:30.000Z","size":69,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T21:23:35.858Z","etag":null,"topics":["mcp-client","mcp-server"],"latest_commit_sha":null,"homepage":"https://www.powershellgallery.com/packages/MCP","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chadnpc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-15T15:39:00.000Z","updated_at":"2025-03-31T20:07:34.000Z","dependencies_parsed_at":"2025-08-14T12:37:41.286Z","dependency_job_id":null,"html_url":"https://github.com/chadnpc/MCP","commit_stats":null,"previous_names":["chadnpc/mcp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chadnpc/MCP","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadnpc%2FMCP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadnpc%2FMCP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadnpc%2FMCP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadnpc%2FMCP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chadnpc","download_url":"https://codeload.github.com/chadnpc/MCP/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadnpc%2FMCP/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270421790,"owners_count":24580814,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-14T02:00:10.309Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mcp-client","mcp-server"],"created_at":"2025-03-17T20:19:14.625Z","updated_at":"2025-08-14T12:37:41.523Z","avatar_url":"https://github.com/chadnpc.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿## [![MCP](docs/images/MCP.png)](https://www.powershellgallery.com/packages/MCP)\n\nA PowerShell module for building MCP-compliant ai agents and tools in your terminal.\n\n\u003c/a\u003e\n\u003ca href=\"https://www.powershellgallery.com/packages/MCP\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\n\u003cimg alt=\"Module Version\" src=\"https://img.shields.io/powershellgallery/v/mcp?include_prereleases\u0026style=plastic\u0026label=MCP.psm1\u0026labelColor=rgba(0%2C%200%2C%200%2C%201)\u0026color=rgba(73%2C%20215%2C%2030%2C%200.7)\"\u003e\n\u003cimg alt=\"Module Downloads\" src=\"https://img.shields.io/powershellgallery/dt/mcp?style=flat\u0026logo=iterm2\u0026labelColor=rgba(0%2C%200%2C%200%2C%201)\u0026color=rgba(73%2C%20215%2C%2030%2C%200.7)\"\u003e\n\u003c/a\u003e\n\n## Installation\n\n```PowerShell\nInstall-Module MCP\n```\n\n## Usage\n\n```PowerShell\nImport-Module MCP\n\n# --- Example Server Setup ---\n# 1. Create a logger instance (caller is responsible for disposing this)\n$serverLogger = New-Logger -MinimumLevel Debug -Logdirectory \"C:\\Logs\\MyMCPServer\"\n# Add a JSON appender for structured logs if desired\n$serverLogger | Add-JsonAppender -FilePath \"C:\\Logs\\MyMCPServer\\server_events.json\"\n\n$server = $null\ntry {\n  # Configure server options and pass the logger\n  $serverOptions = [McpServerOptions]::new(\"MyPowerShellTool\", \"1.2.0\")\n  $serverOptions.Capabilities.Tools = [McpToolsCapability]::new()\n  # Logger is now passed via the parameter in Start-McpServer or MCP::StartServer\n  # $serverOptions.Logger = $serverLogger # No longer set directly in options for start\n\n  Write-Host \"--- MCP PowerShell SDK Example Server ---\"\n\n  # Start the server using the cmdlet, passing the logger\n  $server = Start-McpServer -Options $serverOptions -Logger $serverLogger\n  # Or using the static factory:\n  # $server = [MCP]::StartServer($serverOptions, $serverLogger)\n\n  # Register request handlers\n  $server.RegisterRequestHandler(\"tools/list\", {\n      param($params, $cancellationToken)\n      # Use the logger instance captured in the server object's scope\n      $script:serverLogger.Info(\"Handling tools/list request.\")\n      $tool1 = [McpTool]::new(\"echo_tool\", \"Echoes input.\", @{ type = 'object'; properties = @{ 'input_string' = @{ type = 'string' } }; required = @('input_string') })\n      $tool2 = [McpTool]::new(\"get_date\", \"Returns current date.\", @{ type = 'object'; properties = @{} })\n      return [McpListToolsResult]@{ Tools = @($tool1, $tool2) }\n    }\n  )\n  $server.RegisterRequestHandler(\"tools/call\", {\n      param($paramsRaw, $cancellationToken)\n      $callParams = [McpJsonUtilities]::DeserializeParams($paramsRaw, [McpCallToolRequestParams])\n      $script:serverLogger.Info(\"Handling tools/call for '$($callParams.Name)'.\")\n      $response = [McpCallToolResponse]::new()\n      if ($callParams.Name -eq \"echo_tool\") {\n        $inputText = $callParams.Arguments.input_string\n        $response.Content.Add([McpContent]@{ Type = 'text'; Text = \"Server echoed: $inputText\" })\n      } elseif ($callParams.Name -eq \"get_date\") {\n        $response.Content.Add([McpContent]@{ Type = 'text'; Text = \"Current date: $(Get-Date)\" })\n      } else {\n        $response.IsError = $true\n        $response.Content.Add([McpContent]@{ Type = 'text'; Text = \"Unknown tool: $($callParams.Name)\" })\n      }\n      return $response\n    }\n  )\n\n  Write-Host \"Server started. Waiting for client...\"\n  Write-Host \"Check logs in C:\\Logs\\MyMCPServer\"\n  Write-Host \"Press Ctrl+C to stop.\"\n\n  # Keep alive loop (check endpoint status)\n  while ($server.IsConnected) {\n    Write-Progress \"Listening\" -Status \"...\"\n    Start-Sleep -Seconds 1\n    # Access the internal endpoint's job state for monitoring (use cautiously)\n    if ($server._endpoint._messageProcessingJob -and $server._endpoint._messageProcessingJob.State -eq 'Failed') {\n      $script:serverLogger.Error(\"Server processing job failed!\", $server._endpoint._messageProcessingJob.Error[0].Exception)\n      break\n    }\n  }\n} catch {\n  # Log the failure using the logger\n  $serverLogger.Fatal(\"Server failed to start or run.\", $_.Exception)\n  Write-Error \"Server failed: $($_.Exception.ToString())\"\n} finally {\n  if ($null -ne $server) {\n    Write-Host \"Shutting down server...\"\n    $server.Dispose()\n  }\n  if ($null -ne $serverLogger) {\n    Write-Host \"Disposing server logger...\"\n    $serverLogger.Dispose()\n  }\n}\n\n\n# --- Example Client Usage ---\n$clientLogger = New-Logger -MinimumLevel Debug -Logdirectory \"C:\\Logs\\MyMCPClient\"\n\n$client = $null\ntry {\n  # Assume server script is \"path/to/your/server/script.ps1\"\n  $client = New-McpClient `\n    -Command \"pwsh\" `\n    -Arguments @(\"-File\", \"path/to/your/server/script.ps1\") `\n    -Logger $clientLogger\n  # Or using the static factory:\n  # $clientOptions = [McpClientOptions]::new() # Options are optional\n  # $client = [MCP]::CreateClient(...) -Logger $clientLogger\n\n  Write-Host \"Client connected to Server: $($client.ServerInfo.Name) v$($client.ServerInfo.Version)\"\n  $clientLogger.Info(\"Client connected successfully.\")\n\n  # Example: List tools\n  $listToolsJob = $client.ListAllToolsAsync()\n  $listToolsJob | Wait-Job\n  if ($listToolsJob.State -eq 'Completed') {\n    $allTools = $listToolsJob | Receive-Job\n    Write-Host \"Available Tools:\"\n    $allTools.ForEach({ Write-Host \"- $($_.Name): $($_.Description)\" })\n    $clientLogger.Debug(\"Successfully listed $($allTools.Count) tools.\")\n  } else {\n     $errorMsg = \"Failed to list tools: $($listToolsJob.Error[0].Exception.Message)\"\n     $clientLogger.Error($errorMsg, $listToolsJob.Error[0].Exception)\n     Write-Error $errorMsg\n  }\n  $listToolsJob | Remove-Job\n\n  # Example: Call echo tool\n  $echoArgs = @{ input_string = \"Hello from PowerShell Client!\" }\n  $callJob = $client.CallToolAsync(\"echo_tool\", $echoArgs)\n  $callJob | Wait-Job\n  if ($callJob.State -eq 'Completed') {\n    $callResult = $callJob | Receive-Job\n    Write-Host \"CallTool Result: $($callResult.Content[0].Text)\"\n    $clientLogger.Debug(\"Successfully called 'echo_tool'. Result: $($callResult.Content[0].Text)\")\n  } else {\n     $errorMsg = \"Failed to call tool 'echo_tool': $($callJob.Error[0].Exception.Message)\"\n     $clientLogger.Error($errorMsg, $callJob.Error[0].Exception)\n     Write-Error $errorMsg\n   }\n  $callJob | Remove-Job\n\n} catch {\n  # Log the failure using the logger\n  $clientLogger.Fatal(\"Client operation failed.\", $_.Exception)\n  Write-Error \"Client failed: $($_.Exception.ToString())\"\n} finally {\n  if ($null -ne $client) {\n    Write-Host \"Closing client...\"\n    $client.Dispose()\n  }\n  if ($null -ne $clientLogger) {\n    Write-Host \"Disposing client logger...\"\n    $clientLogger.Dispose()\n  }\n}\n```\n\n## License\n\nThis project is licensed under the [WTFPL License](LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchadnpc%2Fmcp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchadnpc%2Fmcp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchadnpc%2Fmcp/lists"}