# MCP Server

**Identifier:** `PowerShellUniversal.Plugin.MCP`

The Model Context Protocol is a mechanism for communicating with AI agents, like GitHub Copilot. You can enable this MCP plugin to expose your scripts as an MCP AI agent tool.

Tools will include the following information to AI agents:

* Script title
* Description
* Parameters with name, type, help text, and mandatory flag.

## Creating a Tool

You can create a `mcpTools.ps1` file in your `.universal` folder to create new MCP Tools.&#x20;

{% code overflow="wrap" %}

```powershell
New-PSUMCPTool -Name "Get Processes" -Description "Return the processes running on the PowerShell Universal Server" -ScriptFullPath "GetProcesses.ps1"
```

{% endcode %}

Tools can be restricted to authenticated users and roles.

{% code overflow="wrap" %}

```powershell
New-PSUMCPTool -Name "Get Processes" -Description "Return the processes running on the PowerShell Universal Server" -ScriptFullPath "GetProcesses.ps1" -Authenticated -Role @("Administrator")
```

{% endcode %}

## Access in GitHub Copilot

You can provide GitHub Copilot to your PowerShell Universal scripts by configuring the AI agent in VS Code.

In this example, we are using a script with a single call to Get-Process.

```powershell
Get-Process | Select-Object Name, Id
```

With the MCP plugin enabled, we can configure GitHub Copilot. You will need the extension installed before continuing. In VS Code, press `Ctrl+Shift+P` and search for `MCP: Add Server...`.

Select the HTTP option and enter the URL to the MCP server endpoint. You will need the `/api/v1/mcp` route. The full URL, by default, is `http://localhost:5000/api/v1/mcp`. Name the server whatever you would like.

The resulting `settings.json` contents will look something like this.

```json
"mcp": {
    "servers": {
        "PSU": {
            "url": "http://localhost:5000/api/v1/mcp"
        }
    }
}
```

If you are using tools that require authentication, you will need to use the `/api/v1/mcp/secure` endpoint and pass an App Token in the headers.

{% code overflow="wrap" %}

```json
"mcp": {
    "servers": {
        "PSU": {
            "url": "http://localhost:5000/api/v1/mcp/secure",
            "headers": {
                "Authorization": "Bearer token"
            }
        }
    }
}
```

{% endcode %}

If the server is configured properly, the Copilot plugin will list the number of tools.

<figure><img src="/files/gZiIKVS8dNCjuFqMMeiM" alt=""><figcaption></figcaption></figure>

With VS Code configured, we can now use our AI agent tool. Click the Copilot icon and open a new chat.

<figure><img src="/files/1lVicRGUSlTCphkjZJ2e" alt=""><figcaption></figcaption></figure>

Within the chat window, you can prompt Copilot with a question such as `Can you please list all the processes as an array of strings in a new PowerShell scripts?` Copilot will call our PSU tool and retrieve the list of processes and then generate a PowerShell script in VS Code.

<figure><img src="/files/s450NN0YOUfEiyxcQxyI" alt=""><figcaption></figcaption></figure>

Because we also have an endpoint to start processes, you can also prompt Copilot to do so with a statement like: `Can you start a new process in PowerShell Universal named calc?`. This will cause the `calc.exe` process to start because the PSU endpoint will be called with that argument.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.powershelluniversal.com/platform/plugins/mcp-server.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
