DEV Community

smura
smura

Posted on

Deploying Snowflake Cortex Agent and Knowledge Graph with ServiceNow MCP Server

Introduction

ServiceNow provides a feature called MCP Server. It allows various capabilities registered in ServiceNow, such as flows and knowledge graphs, to be exposed as callable tools that AI agents such as Claude Code can invoke directly.

This article documents the steps used to build the following environment:

  • Enable natural-language queries against hardware asset management data stored in Snowflake using Cortex Agent and a Semantic View
  • Enable natural-language queries against software asset management data stored in ServiceNow using Knowledge Graph
  • Register both capabilities as tools in ServiceNow MCP Server
  • Connect to ServiceNow MCP Server from Claude Code, acting as an MCP Client, and submit natural-language queries to obtain answers

The final objective is to let a user ask a single AI agent a question such as, “What assets are managed by Tim?” and receive an answer spanning both the hardware assets in Snowflake and the software assets in ServiceNow. The advantage of this architecture is that users do not need to know where the data is stored, whether in Snowflake or ServiceNow.

All instance URLs and account names in this article have been replaced with placeholders such as <your-instance>. When implementing this architecture, replace them with the values for your own environment.

Overall Architecture

Claude Code (MCP Client)
        │  MCP protocol (OAuth authentication)
        ▼
ServiceNow
 ├─ MCP Server (gateway for tools)
 │   ├─ Tool: Subflow ── Invokes Snowflake Cortex Agent
 │   └─ Tool: Knowledge Graph ── Searches data in ServiceNow
 │
 └─ Snowflake, accessed through the subflow
      ├─ Cortex Agent
      └─ Semantic View (HARDWARE / ADMIN tables)
Enter fullscreen mode Exit fullscreen mode
  • Hardware asset information is stored in Snowflake, while software asset information is stored separately in ServiceNow.
  • ServiceNow MCP Server acts as the entry point and selects between two internal tools: one that queries Snowflake and another that searches data in ServiceNow.
  • The MCP Client, Claude Code in this example, only needs to submit a question. It does not need to know where each tool stores its data.

Prerequisites: Key Terms

Before proceeding with the implementation, this section summarizes the terms used throughout the article. Return here if you encounter an unfamiliar term.

Term Description
MCP (Model Context Protocol) A standard protocol that allows AI agents to invoke external tools and data sources. An MCP Server provides tools, while an MCP Client, Claude Code in this example, consumes them.
Cortex Agent An AI agent capability provided by Snowflake. It receives a natural-language query, uses a Semantic View to construct SQL, retrieves data from tables, and returns an answer.
Semantic View A definition that adds business meaning to table columns and relationships, such as identifying an administrator name or an asset name. By using a Semantic View, Cortex Agent can construct SQL from natural language without directly relying on the physical table structure.
ServiceNow Knowledge Graph A ServiceNow capability that connects tables through edges and makes the resulting graph structure searchable using natural language. Within ServiceNow, it plays a role similar to the combination of a Snowflake Semantic View and Cortex Agent.
Subflow A reusable unit of processing created in ServiceNow Flow Designer and invoked by other flows. In this implementation, the Cortex Agent invocation is encapsulated in a subflow.

Building the Snowflake Components

To use Cortex Agent, first create an entry point in Snowflake that accepts OAuth authentication from ServiceNow. You must also create the Semantic View that gives business meaning to the data, as well as a runtime user and the permissions required to query the agent.

Create the Security Integration and Retrieve Credentials

Open a Snowsight worksheet using the ACCOUNTADMIN role and run the following SQL. This configuration allows Snowflake to accept OAuth authentication from ServiceNow.

-- 01. OAuth settings
USE ROLE ACCOUNTADMIN;
CREATE OR REPLACE SECURITY INTEGRATION _cortex_oauth_2
  TYPE = OAUTH
  ENABLED = TRUE
  OAUTH_CLIENT = CUSTOM
  OAUTH_CLIENT_TYPE = 'CONFIDENTIAL'
  OAUTH_REDIRECT_URI = 'https://<your-instance>.service-now.com/oauth_redirect.do'
  OAUTH_ISSUE_REFRESH_TOKENS = TRUE
  OAUTH_REFRESH_TOKEN_VALIDITY = 7776000 -- Refresh-token lifetime in seconds, up to 90 days
  COMMENT = 'OAuth integration for ServiceNow Cortex Agent Integration'
;
Enter fullscreen mode Exit fullscreen mode

OAUTH_CLIENT_TYPE = 'CONFIDENTIAL' assumes that the client secret can be stored securely on the ServiceNow server side. A PUBLIC client is used for environments such as browsers or mobile applications where a secret cannot be protected. Because this implementation is a server-to-server integration, CONFIDENTIAL is selected.

After creating the security integration, retrieve the Client ID and Client Secret.

-- 02. Check the Client Secret and Client ID
SELECT SYSTEM$SHOW_OAUTH_CLIENT_SECRETS('_CORTEX_OAUTH_2');
Enter fullscreen mode Exit fullscreen mode

Keep these values available because they will be used in the ServiceNow Application Registry configuration.

Load the Data

Create the database and schema that will contain the managed data.

USE ROLE SYSADMIN;
CREATE DATABASE management;
CREATE SCHEMA hardware;
Enter fullscreen mode Exit fullscreen mode

Create the following two tables in this schema and load the sample data.

  • ADMIN: Contains administrator IDs and administrator names.
admin_id admin_name
IT0001 Tim
IT0002 Chester
IT0003 Arlon
IT0004 Michel
IT0005 Lick
IT0006 Len
IT0007 Eathon
  • HARDWARE: Contains asset names, descriptions, vendors, administrator IDs, and related information.
admin_id asset_name vender description
IT0001 MacBook Pro 14 Apple Laptop for sales and proposal activities
IT0002 Dell Latitude 7450 Dell Windows laptop for internal business operations
IT0003 ThinkPad X1 Carbon Lenovo Laptop for data analysis and customer support
IT0004 Surface Laptop 7 Microsoft PC for meetings and presentations
IT0005 ProBook 440 G11 HP PC for general administration and remote work
IT0006 iPhone 16 Apple Smartphone for business communication and multi-factor authentication
IT0007 Galaxy Tab S10 Samsung Tablet for on-site viewing and mobile approvals
IT0001 Dell UltraSharp U2723QE Dell 27-inch external monitor for remote work
IT0003 MX Keys S Logitech Wireless keyboard for data entry
IT0006 Jabra Evolve2 65 Jabra Wireless headset for online meetings

Create the Semantic View

Create a Semantic View so that the loaded table data can be queried using natural language.

  • From the home page, select AI & ML > Analyst > Create in Workspace.
  • Select Guided Wizard.

  • Add MANAGEMENT.HARDWARE.ADMIN and MANAGEMENT.HARDWARE.HARDWARE as the tables.

  • Select all imported tables and columns.

  • Set the Semantic View name to SV_HARDWARE_ADMIN.
  • Set the save location to MANAGEMENT.HARDWARE.

In the editor for SV_HARDWARE_ADMIN, configure the following:

  • Under Relationships, link the ADMIN_ID columns in the two tables. This allows the agent to understand which administrator is responsible for each asset.

  • Under Verified queries, register representative questions and their corresponding SQL statements in advance. This is an important way to improve the agent's response accuracy. It effectively teaches the agent an FAQ with model answers.

  • Question: What hardware assets are managed by each administrator?

  • SQL:

  SELECT a.ADMIN_NAME, h.ASSET_NAME, h.DESCRIPTION, h.VENDER
  FROM admin AS a
  JOIN hardware AS h ON a.ADMIN_ID = h.ADMIN_ID;
Enter fullscreen mode Exit fullscreen mode

Create the Cortex Agent

Next, create the agent that provides the external endpoint and selects the appropriate tool.

  • From the home page, select AI & ML > Agent Studio.
  • Select Create Agent.
  • Create an agent named SEARCH_AGENT in MANAGEMENT.HARDWARE.
  • Configure the settings as follows.

Under Instructions, configure:

  • Model: Claude Sonnet 5
  • Orchestration instructions:
    • Check the administrator and hardware tables.
    • Select the administrator user name.
    • Select the hardware name, vendor, and description related to the administrator ID.
    • Return the results.
  • Response instructions:
    • Search for administrators and their hardware assets.

Under Tools, select Add semantic view and add the previously created SV_HARDWARE_ADMIN. This allows the agent to access data safely through the business definitions in the Semantic View rather than writing SQL without semantic context.

Finally, use Preview to test a question such as “Check the hardware managed by Tim” and verify that the expected answer is returned.

Grant Permissions to the Runtime User

Grant the end user connecting from ServiceNow permission to execute Cortex Agent and access the required resources. A dedicated role and service account are used to follow the principle of least privilege, exposing only the permissions needed for the external integration. Using an administrator role for the ServiceNow connection could permit unintended operations.

-- 04. Create the role and grant permissions
USE ROLE SECURITYADMIN;

CREATE ROLE cortex_agent_hardware_search;
GRANT DATABASE ROLE SNOWFLAKE.CORTEX_AGENT_USER TO ROLE cortex_agent_hardware_search;
GRANT DATABASE ROLE SNOWFLAKE.CORTEX_USER TO ROLE cortex_agent_hardware_search;
GRANT USAGE ON DATABASE management TO ROLE cortex_agent_hardware_search;
GRANT USAGE ON SCHEMA management.hardware TO ROLE cortex_agent_hardware_search;
GRANT USAGE ON AGENT management.hardware.search_agent TO ROLE cortex_agent_hardware_search;
GRANT USAGE ON WAREHOUSE compute_wh TO ROLE cortex_agent_hardware_search;
GRANT USAGE ON DATABASE MANAGEMENT TO ROLE cortex_agent_hardware_search;
GRANT USAGE ON SCHEMA MANAGEMENT.HARDWARE TO ROLE CORTEX_AGENT_HARDWARE_SEARCH;
GRANT USAGE ON SEMANTIC VIEW MANAGEMENT.HARDWARE.SV_HARDWARE_ADMIN TO ROLE CORTEX_AGENT_HARDWARE_SEARCH;
GRANT SELECT ON SEMANTIC VIEW MANAGEMENT.HARDWARE.SV_HARDWARE_ADMIN TO ROLE CORTEX_AGENT_HARDWARE_SEARCH;
GRANT SELECT ON TABLE MANAGEMENT.HARDWARE.HARDWARE TO ROLE CORTEX_AGENT_HARDWARE_SEARCH;
GRANT SELECT ON TABLE MANAGEMENT.HARDWARE.ADMIN TO ROLE CORTEX_AGENT_HARDWARE_SEARCH;

-- Grant the role to the user
CREATE USER servicenow
    PASSWORD = '<your_password>'
    DEFAULT_ROLE = cortex_agent_hardware_search
    MUST_CHANGE_PASSWORD = FALSE
    COMMENT = 'Service account for ServiceNow integration';

GRANT ROLE cortex_agent_hardware_search TO USER servicenow;
GRANT ROLE sysadmin TO USER servicenow;
Enter fullscreen mode Exit fullscreen mode

Configure Authentication in ServiceNow

Use ServiceNow's standard OAuth integration capabilities to connect securely from ServiceNow to Snowflake. ServiceNow OAuth integration uses three layers, each with a different role:

  1. Define the external provider in Application Registry.
  2. Issue and obtain authentication information through Credentials.
  3. Define the actual destination through Connection & Credential Alias.

Configure the Snowflake Security Integration in Application Registry

  1. In ServiceNow, go to System OAuth > Application Registry and select New.
  2. Select Connect to a third party OAuth Provider.
  3. Configure the following values.
Field Value
Name Snowflake Cortex Agents OAuth 2.0
Client ID Client ID issued by Snowflake
Client Secret Client Secret issued by Snowflake
Default Grant type Authorization Code
Authorization URL https://<your-account>.snowflakecomputing.com/oauth/authorize
Token URL https://<your-account>.snowflakecomputing.com/oauth/token-request
Redirect URL https://<your-instance>.service-now.com/oauth_redirect.do

This step registers the definition that tells ServiceNow which credentials to use when authenticating with Snowflake as an OAuth provider. It does not yet establish a connection or issue an authentication token.

Configure Connection & Credential Alias

Configure the Credential

  1. Go to Connections & Credentials > Credentials and select New.
  2. Select OAuth 2.0 Credentials.
  3. Configure the following values.
Field Value
Name Snowflake Cortex Agents User Credential
OAuth Entity Profile Entity Profile for Snowflake Cortex Agents OAuth 2.0 created in Application Registry
Integration Type Personal

Save the configuration, then select Get OAuth Token to obtain an authentication token and store it in ServiceNow. At this point, the OAuth flow defined in Application Registry runs for the first time, including browser-based login and consent, and a token is issued.

Configure the Credential Alias and Connection

  1. Go to Connections & Credentials > Connection & Credential Aliases and select New.
  2. Configure the following value.
Field Value
Name Snowflake OAuth Cortex Agents Alias

  1. Save the configuration, then create a connection from the Connections tab.
  2. Configure the following values.
Field Value
Name Snowflake Cortex Agents HTTP Connection
Credential Snowflake Cortex Agents User Credential
Connection URL https://<your-account>.snowflakecomputing.com

Connection & Credential Alias provides an abstraction that Flow Designer can reference to determine which connection information to use for an HTTP request. If the destination or credential changes, the flow implementation does not need to be modified as long as the alias continues to resolve to the appropriate connection.

Configure Cortex Agent Execution in ServiceNow

Implement the ServiceNow Action That Invokes Cortex Agent

Snowflake Cortex Agent is invoked through the agent:run REST API.

  1. Go to Process Automation > Flow Designer.
  2. From New, select Action and name the action Ask Snowflake Cortex Agent.
  3. Configure it as follows.

Input variable definition

Label Type
user_prompt String

Action step definition

  • Step 1

    • Action: REST
    • Name: Cortex Agents Action
    • Connection Details:
    • Connection: Use Connection Alias
    • Connection Alias: Snowflake_OAuth_Cortex_Agents_Alias
    • Request Details:
    • Build Request: Manually
    • Resource Path: /api/v2/databases/management/schemas/hardware/agents/search_agent:run
    • HTTP Method: POST
    • Request headers, shown in the UI as Name/Label:
      • Content-Type / application/json
      • Accept / application/json
    • Request Content:
    • Request Type: Text
    • Request Body:
      {
        "stream": false,
        "messages": [
          {
            "role": "user",
            "content": [
              {
                "type": "text",
                "text": "{{input user_prompt}}"
              }
            ]
          }
        ]
      }
    


  • Step 2

    • Action: Script
    • Name: Return Output
    • Input Variables, shown as Name / Value:
    • response_body / <step1 cortex agent action - response_body>
    • status_code / <step1 cortex agent action - status_code>
    • Script:
    (function execute(inputs, outputs) {
      if (inputs.status_code != 200) {
        outputs.error = "Error: HTTP " + inputs.status_code + " - " + inputs.response_body;
        outputs.answer = "";
        return;
      }
    
      try {
        var response = JSON.parse(inputs.response_body);
        var answerText = "";
    
        // Extract text from the content array in the non-streaming response
        if (response.content && response.content.length > 0) {
          for (var i = 0; i < response.content.length; i++) {
            if (response.content[i].type === "text") {
              answerText += response.content[i].text;
            }
          }
        }
    
        outputs.answer = answerText;
        outputs.error = "";
      } catch (e) {
        outputs.error = "Failed to parse response: " + e.message;
        outputs.answer = "";
      }
    })(inputs, outputs);
    
    • Output Variables, shown as Label / Type:
    • answer / String
    • error / String



Action output variable definition

Label Type Value
answer String <step2 return output - answer>
error String <step2 return output - error>

Finally, select Publish.

Configure the Subflow and Action Invocation

The action is invoked through a subflow rather than used directly so that the execution user's context is preserved. Calls from MCP Server should execute while retaining the identity of the user who submitted the question. This behavior is controlled through the subflow's Run As setting.

  1. From the Flow Designer home page, select New and create a subflow.
  2. Configure it as follows.
Field Value
Name Hardware Search Cortex Agents Sub Flow
Run As User who initiates session

Input and output variables

  • Input, shown as Label / Type: user_prompt / String
  • Outputs, shown as Label / Type: answer / String and error / String

Actions

  • Action 1: Invoke Ask Snowflake Cortex Agent. For the Snowflake OAuth Cortex Agents Alias connection, select Use Default Connection.

  • Action 2: Assign the subflow outputs:
    • answer / <1 Ask Snowflake Cortex Agent - answer>
    • error / <1 Ask Snowflake Cortex Agent - error>

Select Test, enter What kind of hardware is managed by Tim?, and verify that the expected value is returned. Finally, select Publish.


Configure Permissions for the Subflow

Finally, configure permissions so that an external AI agent can invoke this subflow through an MCP Client.

  1. From Elevate Role, select security_admin.
  2. On the subflow properties page, select Managed Security.
  3. Add a new access control with the following settings.
Field Value
Type flow
Operation invoke_from_ai
Decision Type Allow If
Role snc_internal



The dedicated invoke_from_ai operation makes it possible to distinguish between execution by a person through the UI and execution by an AI agent through MCP. Calls from AI can therefore be allowed or restricted independently of ordinary flow execution permissions.

The ServiceNow subflow configuration is now complete.

Configure ServiceNow Knowledge Graph

Software asset information is stored in ServiceNow tables, so natural-language search is implemented differently from the Snowflake part of the architecture. ServiceNow Knowledge Graph defines relationships between tables as a graph, allowing the data to be traversed through natural-language queries.

Import the Tables

Prepare an Excel file and import the following tables through App Engine Studio.

  • admin: When configuring the admin_id column, select Display, then complete the import.
  • software: When configuring the admin_id column, set its referenced table to admin, then complete the import.
admin_id software_name vendor description
IT0001 Microsoft 365 Apps Microsoft Productivity suite for document creation, email, and collaboration
IT0002 Slack Salesforce Business messaging and team communication platform
IT0003 Tableau Desktop Salesforce Data visualization and dashboard development software
IT0004 Microsoft Teams Microsoft Online meetings, chat, and collaboration software
IT0005 Adobe Acrobat Pro Adobe PDF creation, editing, and electronic document management
IT0006 Microsoft Authenticator Microsoft Multi-factor authentication and secure account access application
IT0007 ServiceNow Mobile ServiceNow Mobile access for workflow tasks, approvals, and service requests
IT0001 Salesforce Sales Cloud Salesforce Customer relationship management software for sales activities
IT0003 Visual Studio Code Microsoft Source code editor for development and data-related scripts
IT0006 Jabra Direct Jabra Device management software for Jabra headsets and firmware updates

Configure Knowledge Graph

  1. Open Knowledge Graph > Knowledge Graph Designer and create a knowledge graph named software admin graph.
  2. Add an edge from the software table to the admin table. Registering the relationship between tables connected through a reference column as an edge improves the accuracy of natural-language queries.

  1. Select Test Schema, enter What kind of software is managed by Tim?, and verify that the expected result is returned.

The ServiceNow Knowledge Graph configuration is now complete.

Configure ServiceNow MCP Server

Configure MCP Server

  1. Go to All > MCP Server Console.
  2. Under Servers, select Create Server.
  3. Configure the following values.
Field Value
Label assets-admin-ask
Short Description This MCP server manages the administrators of hardware and software assets. Hardware assets and administrators are stored in Snowflake, while software assets and administrators are stored in ServiceNow Knowledge Graph.

Configure the Tools

Under Tools, select Create Tool and create the following two tools. This configuration presents the Snowflake data and ServiceNow data to users as two tools within a single MCP Server.

  • Create a tool in the Knowledge Graph category:
    • Label: software admin graph
    • Description: Search for software administrators and assets in ServiceNow Knowledge Graph.
    • MCP Server: assets-admin-ask
  • Create a tool in the Subflow category:
    • Label: Hardware Search Cortex Agents Sub Flow
    • Description: Search for hardware assets and their administrators.
    • MCP Server: assets-admin-ask

Configure the Inbound Integration for Authentication

OAuth authentication is also required when the MCP Client, Claude Code, connects to ServiceNow MCP Server. In this flow, ServiceNow accepts OAuth requests from an external client, so configure it as an inbound integration.

  1. Go to System OAuth > Inbound integrations and select New Integration.
  2. Configure the following values.
Field Value
Name assets_admin_ask
Provider Name ServiceNow
Redirect URLs http://localhost:8080/callback

When Claude Code connects to a remote MCP Server through OAuth, it starts a temporary local web server to receive the authorization callback and token. By default, a random port may be used. Because a fixed redirect URL must be registered in the ServiceNow inbound integration in advance, use the --callback-port option to fix the port number.

This implementation uses port 8080. Add the following URL to Redirect URLs in the assets_admin_ask inbound integration created above:

http://localhost:8080/callback
Enter fullscreen mode Exit fullscreen mode

Configure the Claude MCP Client and Connect to MCP Server

The ServiceNow-side preparation is now complete. Finally, configure Claude Code through its VS Code extension and connect to the MCP Server in ServiceNow.

Register MCP Server with claude mcp add

Using the Client ID and Client Secret issued for the inbound integration, register the MCP Server through the Claude Code CLI.

claude mcp add --transport http \
  --client-id <Client ID issued by the inbound integration> \
  --client-secret \
  --callback-port 8080 \
  --scope user \
  servicenow-mcp \
  https://<your-instance>.service-now.com/sncapps/mcp-server/mcp/<mcp-server-name>
Enter fullscreen mode Exit fullscreen mode
  • Do not write the Client Secret directly on the command line. Specify --client-secret without a value and enter the secret interactively when prompted, preventing it from being stored in shell history.
  • Specifying --scope user registers the server as a global user-level configuration rather than limiting it to a particular project directory. If --scope is omitted, the configuration is local to the project and will not be visible to Claude Code sessions started from another directory.
  • In the URL, <mcp-server-name> is the path name corresponding to the server created in MCP Server Console, in this example assets-admin-ask.

This command only registers the configuration. It does not open a browser at this stage. The OAuth authorization flow is started explicitly in the next step.

Run the OAuth Authorization Flow

Check the authentication state of the registered server with:

claude mcp list
Enter fullscreen mode Exit fullscreen mode

If servicenow-mcp is displayed as ! Needs authentication, the configuration has been registered but authentication has not yet been completed. To begin authentication, run the following command in an interactive Claude Code session:

/mcp
Enter fullscreen mode Exit fullscreen mode

Select servicenow-mcp from the list, then select Authenticate. A browser opens and displays the ServiceNow login and authorization page. After authorization, the browser is redirected to http://localhost:8080/callback, the token is passed to Claude Code, and authentication is completed.

Run claude mcp list again. If servicenow-mcp is displayed as ✔ Connected, the connection is complete.

Finally, ask for the software and hardware assets managed by Tim and verify that the correct results are returned. In Claude Code, the result should look similar to the following.

Conclusion

This implementation uses ServiceNow MCP Server to provide seamless natural-language access from a single AI agent, Claude Code, to two data sources with different storage locations and query mechanisms: Snowflake Cortex Agent for hardware asset management and ServiceNow Knowledge Graph for software asset management.

ServiceNow MCP Server makes it possible to invoke both native ServiceNow assets and external tools efficiently through a unified interface.

Top comments (0)