Deploying Snowflake Cortex Agent and Knowledge Graph with ServiceNow MCP Server
DEV Community

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)

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.

  • 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';

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');

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;

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;

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
Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.