
FastMCP-Powershell
FASTMCP的PowerShell实现 - 模型上下文协议(MCP)的人体工程学接口
3 years
Works with Finder
1
Github Watches
0
Github Forks
1
Github Stars
FastMCP for PowerShell
A PowerShell implementation of FastMCP - An ergonomic interface for the Model Context Protocol (MCP).
Overview
FastMCP for PowerShell provides a streamlined way to work with the Model Context Protocol, enabling efficient interaction with AI models through a clean, PowerShell-native interface. This module helps you create, manage, and utilize model contexts with structured tools, resources, and prompts.
Installation
From PowerShell Gallery (Recommended)
Install-Module -Name FastMCP
Manual Installation
- Clone this repository
- Import the module directly:
Import-Module "d:\path\to\FastMCP-PowerShell\FastMCP.psd1"
Quick Start
# Import the module
Import-Module FastMCP
# Create a new server instance and test connectivity
$server = New-FastMCPServer -Endpoint "https://api.example.com/v1" -ApiKey "your-api-key"
if ($server.TestConnection()) {
Write-Output "Server is reachable!"
} else {
Write-Output "Server connection failed."
}
# Get a context and add tools, resources, and prompts as needed
$context = Get-FastMCPContext -Server $server
# Simulate sending a request
$response = $context.SendRequest("What is the current weather?")
Write-Output $response.Content
# (Optional) Simulate reporting progress during a long task
for ($i = 10; $i -le 100; $i += 30) {
$progress = @{ Operation = "Example Task"; PercentComplete = $i; Timestamp = (Get-Date) }
$context.ReportProgress($progress)
Start-Sleep -Seconds 1
}
Core Concepts
FastMCP is built around these key concepts:
- Server - The connection to the underlying AI model API
- Context - The working environment for interacting with models
- Tools - Functions that models can use to perform actions
- Resources - Data assets like images, documents, or databases
- Prompts - Templates for structuring requests to models
Function Reference
New-FastMCPServer
Creates a new FastMCP server instance that connects to a model provider.
New-FastMCPServer -Endpoint "https://api.openai.com/v1" -ApiKey $env:OPENAI_API_KEY -Provider "OpenAI"
Parameters:
-
Endpoint
: The API endpoint URL -
ApiKey
: Your API authentication key -
Provider
: The model provider (optional, defaults to "OpenAI") -
Model
: The model to use (optional, defaults to provider's recommended model) -
Options
: Additional options as hashtable (optional)
New-Image
Creates an image resource for use with the model.
Example 1: Create an image from a file path
New-Image -Path "./diagram.png" -Description "System architecture diagram"
Example 2: Create a named image (for testing purposes)
New-Image -Name "Diagram" -Description "System architecture diagram"
Example 3: Create an image with both name and path (even if the file doesn't exist)
New-Image -Name "TestImage" -Path "C:\path\to\image.jpg" -Description "Test image" -CreateIfNotExists
Parameters:
-
Name
: A unique name for the image (used in testing or placeholder scenarios) -
Description
: A description of the image content -
Path
: File path to the image (used for actual image resources) -
Tags
: Optional array of tags for categorization -
CreateIfNotExists
: Create an image object even if the file doesn't exist at the specified path
New-Tool
Creates a tool that can be used by the model.
New-Tool -Name "WeatherLookup" -Description "Gets current weather for a location" -Function {
param($location)
# Implementation would call a weather API
return @{ temperature = 72; conditions = "Sunny"; location = $location }
}
Parameters:
-
Name
: A unique name for the tool -
Description
: Description of what the tool does -
Function
: ScriptBlock containing the tool's implementation -
Parameters
: Optional parameter definitions -
Tags
: Optional array of tags
New-Resource
Creates a resource that can be referenced by the model.
New-Resource -Name "UserManual" -Description "Product user manual" -Content $manualText -Type "text" -Tags "documentation"
Parameters:
-
Name
: A unique name for the resource -
Description
: Description of the resource -
Content
: The resource content or a path to it -
Type
: The resource type (text, json, binary, etc.) -
Tags
: Optional array of tags
New-Prompt
Creates a prompt template for structuring requests.
New-Prompt -Name "QueryWithContext" -Description "Basic query with context" -RenderScript {
param($query, $additionalContext)
return @"
Context information:
$additionalContext
User query: $query
Please provide a helpful response.
"@
}
Parameters:
-
Name
: A unique name for the prompt -
Description
: Description of the prompt's purpose -
RenderScript
: ScriptBlock that generates the formatted prompt -
Tags
: Optional array of tags
Get-FastMCPContext
Gets a context object for working with the model.
$context = Get-FastMCPContext -Server $server
Parameters:
-
Server
: The FastMCP server instance to use
Advanced Examples
Creating a Multi-Tool Workflow
# Set up tools for a data analysis workflow
$dataLoader = New-Tool -Name "LoadData" -Description "Loads data from CSV" -Function {
param($path)
Import-Csv $path
}
$dataTransformer = New-Tool -Name "TransformData" -Description "Performs data transformations" -Function {
param($data, $operations)
# Implementation of data transformations
# ...
return $transformedData
}
$dataVisualizer = New-Tool -Name "VisualizeData" -Description "Creates data visualizations" -Function {
param($data, $type)
# Implementation of visualization creation
# ...
return $visualizationPath
}
# Create the context and add all tools
$context = Get-FastMCPContext -Server $server
$context.AddTool($dataLoader)
$context.AddTool($dataTransformer)
$context.AddTool($dataVisualizer)
# Create an analysis workflow
$response = $context.SendRequest(@"
Please analyze the data in 'sales_data.csv':
1. Load the data
2. Transform it by aggregating by region and quarter
3. Create a bar chart visualization
4. Interpret the results
"@)
Using Resources and Custom Prompts
# Create a resource with company information
$companyInfo = New-Resource -Name "CompanyInfo" -Description "Company background information" -Content @"
Contoso Ltd. is a multinational corporation founded in 2005.
The company specializes in cloud computing solutions and has
over 10,000 employees across 30 countries.
"@ -Type "text"
# Create a prompt template for answering questions with company context
$companyPrompt = New-Prompt -Name "CompanyQuery" -Description "Query with company context" -RenderScript {
param($query, $companyInfo)
return @"
Company Information:
$companyInfo
Please answer the following question about the company:
$query
"@
}
# Use the context with the resource and prompt
$context = Get-FastMCPContext -Server $server
$context.AddResource($companyInfo)
$context.AddPrompt($companyPrompt)
# Send a request using the prompt
$response = $context.SendRequest("What industry is the company in?", @{
promptName = "CompanyQuery"
promptArgs = @{
companyInfo = $companyInfo.Content
}
})
Logging Configuration
FastMCP includes a comprehensive logging system:
# Import required type
Add-Type -TypeDefinition @"
public enum LogLevel {
DEBUG,
INFO,
WARNING,
ERROR,
CRITICAL
}
"@
# Configure logging
Set-Logging -Level [LogLevel]::DEBUG
# Now all operations will log at DEBUG level
$server = New-FastMCPServer -Endpoint "https://api.example.com/v1" -ApiKey "your-api-key"
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
相关推荐
😎简单易用、🧩丰富生态 -大模型原生即时通信机器人平台| 适配QQ / 微信(企业微信、个人微信) /飞书 /钉钉 / discord / telegram / slack等平台| 支持chatgpt,deepseek,dify,claude,基于LLM的即时消息机器人平台,支持Discord,Telegram,微信,Lark,Dingtalk,QQ,Slack
Reviews

user_E1aPlnZO
As an avid MCP application user, I highly recommend FastMCP-PowerShell by Krolikov-K. This tool has significantly boosted my productivity with its seamless integration and powerful scripting capabilities. Whether you're automating tasks or managing systems, FastMCP-PowerShell delivers exceptional performance. The user-friendly interface and comprehensive functionality make it a standout choice for any PowerShell enthusiast.

user_W99WgqEw
FastMCP-PowerShell by Krolikov-K is an exceptional tool for PowerShell automation enthusiasts. It significantly streamlines scripting tasks and enhances productivity with its intuitive design. Highly recommended for anyone looking to boost their efficiency in managing scripts and commands. An invaluable addition to any PowerShell user's toolkit!