YS

yvain13/servicenow-scripts-mcp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

6 stars 15 forks 质量 56 趋势 14

This repository provides MCP tools for ServiceNow Scripts

概览

This repository contains that work together through the Model‑Context Protocol (MCP): 1. – a FastMCP server exposing CRUD tools for ServiceNow Business Rules, Client Scripts, and Script Includes. 2. – a Gradio UI that talks to the MCP server to generate, edit, and deploy scripts with GPT‑4o. Follow these simple steps to get the solution up and running: Create a file named .env in the root directory with your credentials: Run these commands in separate terminal windows: Open the URL shown in the second terminal (typically http://127.0.0.1:7860) in your web browser. 1. enters an instruction or selects an existing script. 2. (client) calls GPT‑4o or an MCP tool. 3. translates the tool call into a ServiceNow REST request. 4. Results stream back to the UI via HTTP. The mcp_client.py file provides a simple example of how to create an MCPAgent that can communicate with your FastMCP server.

README

以下为原文 README 节选,完整内容请查看原文。

ServiceNow Script Manager

This repository contains two moving pieces that work together through the Model‑Context Protocol (MCP):

  1. sn_mcp_tools.py – a FastMCP server exposing CRUD tools for ServiceNow Business Rules, Client Scripts, and Script Includes.
  2. script_generator.py – a Gradio UI that talks to the MCP server to generate, edit, and deploy scripts with GPT‑4o.

Setup Guide

Follow these simple steps to get the solution up and running:

1. Clone the Repository

git clone https://github.com/yvain13/ServiceNow-Scripts-MCP.git
cd ServiceNow-Scripts-MCP

2. Set Up Python Environment

# Create virtual environment
python -m venv venv

# Activate on macOS/Linux
source venv/bin/activate

# Activate on Windows
# venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

3. Configure Environment Variables

Create a file named .env in the root directory with your credentials:

# OpenAI API Key
OPENAI_API_KEY=sk-your-api-key-here

# ServiceNow Instance Details
SERVICENOW_URL=https://your-instance.service-now.com/
SERVICENOW_USER=your-username
SERVICENOW_PASS=your-password
SERVICENOW_AUTH_TYPE=basic

4. Start the Application

Run these commands in separate terminal windows:

# Terminal 1: Start the FastMCP server
python sn_mcp_tools.py

# Terminal 2: Start the Gradio UI
python script_generator.py

Open the URL shown in the second terminal (typically http://127.0.0.1:7860) in your web browser.


How it works (architecture)

┌───────────────┐       HTTP/MCP        ┌────────────────────────┐
│ Gradio UI     │  ───────────────────▶ │ FastMCP Server         │
│ (script_…py)  │ ◀───────────────────  │ (sn_mcp_tools.py)      │
└───────────────┘       MCP calls       └──────────┬─────────────┘
       ▲  GPT‑4o                                    │ REST API
       │                                            ▼
       └─ openai                                    ServiceNow Table API
  1. User enters an instruction or selects an existing script.
  2. Gradio UI (client) calls GPT‑4o or an MCP tool.
  3. FastMCP server translates the tool call into a ServiceNow REST request.
  4. Results stream back to the UI via HTTP.

Key Files

File Purpose Run with
sn_mcp_tools.py Exposes ServiceNow CRUD operations for scripts via MCP python sn_mcp_tools.py
script_generator.py Gradio UI for script management python script_generator.py
mcp_client.py Example showing how to create an MCPAgent python mcp_client.py
requirements.txt Python dependencies pip install -r requirements.txt

Example MCP Client Usage

在 GitHub 查看完整 README

安装

npx mcp-remote http://localhost:9123/mcp
新手?先看 mcpskill.org 教程 →

配置

# Example usage from mcp_client.py from mcp_use import MCPAgent, MCPClient from langchain_openai import ChatOpenAI # Create a client that connects to the FastMCP server config = { "mcpServers": { "http": { "url": "http://localhost:9123/mcp" } } } client = MCPClient.from_dict(config) # Create the LLM llm = ChatOpenAI(model="gpt-4o") # Create the agent agent = MCPAgent(llm=llm, client=client, max_steps=30) # Run a query that will use the MCP tools result = agent.run("Create a business rule for the incident table that logs when a VIP incident is created") print(result)