<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ram Palagummi on Medium]]></title>
        <description><![CDATA[Stories by Ram Palagummi on Medium]]></description>
        <link>https://medium.com/@rpalagummi?source=rss-858c887b593b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Ram Palagummi on Medium</title>
            <link>https://medium.com/@rpalagummi?source=rss-858c887b593b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 06:45:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rpalagummi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Build Your Own MCP Client APP — Connecting to Snowflake MCP Servers with OAuth and RBAC]]></title>
            <link>https://medium.com/snowflake/connecting-to-snowflake-mcp-servers-with-oauth-2-0-and-role-based-access-control-a-complete-guide-c17d20be8a67?source=rss-858c887b593b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c17d20be8a67</guid>
            <category><![CDATA[snowflake-mcp-client-app]]></category>
            <category><![CDATA[snowflake]]></category>
            <category><![CDATA[build-your-own-mcp-client]]></category>
            <category><![CDATA[mcp-client-oauth-rbac]]></category>
            <category><![CDATA[snowflake-mcp-server]]></category>
            <dc:creator><![CDATA[Ram Palagummi]]></dc:creator>
            <pubDate>Mon, 02 Mar 2026 20:01:00 GMT</pubDate>
            <atom:updated>2026-03-14T01:38:41.070Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Building production-ready MCP Client Apps/AI agents connecting to Snowflake MCP Servers with role-based data access control using Model Context Protocol and OAuth Authorization</em></p><h3>📦 Complete Source Code Available</h3><p>Get the full implementation with setup instructions, SQL scripts, and more <a href="https://github.com/rpalagummi23/mcp_oauth_streamlit_client">from GitHub →</a></p><h3>This article is best if:</h3><p>You want to <strong><em>build your own MCP Client App</em></strong> that authenticates and connects to Snowflake-hosted MCP Servers using OAuth. The pattern works for:</p><ol><li><strong>Web apps</strong> (HTML/JS frontend + any backend — Node, Python, Java, Go, etc.) — <strong>REST API </strong>is implicit</li><li><strong>Streamlit apps</strong> — interactive data apps with a login flow</li><li><strong>Flask / FastAPI / Django</strong> — web backends with user authentication</li><li><strong>Mobile / Desktop apps </strong>— native apps with embedded browsers</li><li><strong>Custom integrations </strong>— any system that needs user-delegated MCP access</li></ol><h3><strong>Introduction</strong></h3><p>As AI-powered applications become the norm, the need for secure, standardized ways to connect these systems to enterprise data has never been greater. Snowflake’s Model Context Protocol (MCP) Servers provide a powerful abstraction layer, enabling AI models and agents to interact with your data through well-defined tools. But here are the critical questions: <em>How do you authenticate users securely when building multi-user AI applications? and How to ensure your users/customers with different roles access only those Snowflake MCP servers that they are authorized to.</em></p><p>Personal Access Tokens (PATs) might seem convenient, but they fall short in production scenarios where you need:</p><ul><li>User-level identity on every request</li><li>Session-based token expiration</li><li>MFA and SSO support</li><li>Proper audit trails for compliance</li></ul><p>Enter OAuth 2.0 Authorization Code Flow with PKCE — the industry-standard approach that solves all of these challenges.</p><p>In this article, I’ll walk you through building a Streamlit-based MCP client that authenticates users via Snowflake’s native OAuth integration. You’ll learn how role-based access control ensures different users can only access the data and tools their roles permit — enabling secure multi-tenant AI applications with proper data governance.</p><h3>The OAuth Flow:</h3><p>Before diving into implementation, let’s visualize how the OAuth Authorization Code Flow with PKCE works when connecting to Snowflake MCP servers:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*tvlf6LH31UM_hIOZWQWEKw.png" /></figure><p>Notice how the role is specified in the OAuth scope at step 2 and remains bound to the token throughout the flow. This ensures that every MCP server request carries the user’s identity and role permissions.</p><h3>Architecture Overview</h3><p>Now let’s look at the system components and how they interact:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*xJAuTPy-TjhCr9HMg-oCIA.png" /></figure><h3>Quick Start: Get Running in 5 Minutes</h3><ol><li><em>Get the complete code from </em><a href="https://github.com/rpalagummi23/mcp_oauth_streamlit_client"><em>Git repository</em></a></li><li><em>Readme file is your best companion</em></li><li><em>Run the SQL scripts in Snowflake</em></li><li><em>Create the MCP Client App from the python code provided (Note: Python code is for Streamlit app but leverage the python functions to create your own application.</em></li><li><em>Follow the steps below for clarity</em></li></ol><h3>Step 1: Set Up Snowflake OAuth Security Integration</h3><p>First, create an OAuth Security Integration in Snowflake. This is the foundation that enables OAuth authentication for your application.</p><p>⚠️ <em>Hostname Warning: When configuring hostnames for MCP server connections, use hyphens (-) instead of underscores (_).</em></p><pre>CREATE OR REPLACE SECURITY INTEGRATION mcp_client_oauth<br>    TYPE = OAUTH<br>    ENABLED = TRUE<br>    OAUTH_CLIENT = CUSTOM<br>    OAUTH_CLIENT_TYPE = &#39;CONFIDENTIAL&#39;<br>    OAUTH_REDIRECT_URI = &#39;https://your-app.example.com/callback&#39;<br>    -- Use OAUTH_ALLOW_NON_TLS_REDIRECT_URI = TRUE only for local development<br>    PRE_AUTHORIZED_ROLES_LIST = (&#39;ANALYST_ROLE&#39;, &#39;DATA_ENGINEER_ROLE&#39;);</pre><h4>Key Parameters Explained</h4><ul><li>OAUTH_CLIENT_TYPE = ‘CONFIDENTIAL’: The client can securely store secrets (server-side app)</li><li>OAUTH_REDIRECT_URI: Where Snowflake redirects after authentication — must match your app URL exactly</li><li>PRE_AUTHORIZED_ROLES_LIST: Roles that can use this integration without additional consent</li></ul><h4>Retrieve Your OAuth Credentials</h4><pre>SELECT SYSTEM$SHOW_OAUTH_CLIENT_SECRETS(&#39;mcp_client_oauth&#39;);</pre><p>This returns your OAUTH_CLIENT_ID and OAUTH_CLIENT_SECRET — store these securely!</p><h3>Step 2: Grant Required Permissions in Snowflake</h3><p>Ensure your roles have access to the MCP server:</p><p>⚠️ <em>Important: Access to the MCP Server does not automatically grant access to the tools. You must grant permissions for each tool’s underlying object (semantic views, Cortex Search services, UDFs, etc.) separately to the role.</em></p><pre>-- Grant integration access<br>GRANT USAGE ON INTEGRATION mcp_client_oauth TO ROLE analyst_role;</pre><pre>-- Grant MCP server access<br>GRANT USAGE ON DATABASE my_database TO ROLE analyst_role;<br>GRANT USAGE ON SCHEMA my_database.my_schema TO ROLE analyst_role;<br>GRANT USAGE ON MCP SERVER my_database.my_schema.my_mcp_server TO ROLE analyst_role;</pre><pre>-- IMPORTANT: Also grant access to the underlying tool objects<br>-- For Cortex Analyst tools (semantic views):<br>GRANT USAGE ON SEMANTIC VIEW my_database.my_schema.my_semantic_view TO ROLE analyst_role;</pre><pre>-- For Cortex Search tools:<br>GRANT USAGE ON CORTEX SEARCH SERVICE my_database.my_schema.my_search_service TO ROLE analyst_role;<br></pre><pre>-- For custom tools (UDFs/Stored Procedures):<br>GRANT USAGE ON FUNCTION my_database.my_schema.my_udf(VARCHAR) TO ROLE analyst_role;</pre><h3>Step 3: Implement PKCE in Python</h3><p>💡 Note: The code snippets below highlight key python implementation details. For the complete, runnable implementation, see the <a href="https://github.com/rpalagummi23/mcp_oauth_streamlit_client">GitHub repository</a>.</p><p>PKCE adds security by generating a cryptographic challenge that links the authorization request to the token exchange. Here’s the implementation:</p><pre>import hashlib<br>import base64<br>import secrets</pre><pre>def generate_pkce_pair():<br>    &quot;&quot;&quot;Generate PKCE code verifier and challenge&quot;&quot;&quot;<br>    # Generate a random code verifier<br>    code_verifier = base64.urlsafe_b64encode(<br>        secrets.token_bytes(32)<br>    ).decode(&#39;utf-8&#39;).rstrip(&#39;=&#39;)<br>    <br>    # Create SHA256 hash of verifier for the challenge<br>    code_challenge = base64.urlsafe_b64encode(<br>        hashlib.sha256(code_verifier.encode(&#39;utf-8&#39;)).digest()<br>    ).decode(&#39;utf-8&#39;).rstrip(&#39;=&#39;)<br>    <br>    return code_verifier, code_challenge</pre><p>The code_verifier is stored securely, and the code_challenge is sent with the authorization request. During token exchange, Snowflake verifies that the code_verifier matches the original challenge.</p><h3>Step 4: Core Authorization Flow Logic</h3><h4>Generate the Authorization URL</h4><pre>def get_authorization_url(/service/state: str, code_challenge: str) -&gt; str:<br>    &quot;&quot;&quot;Generate OAuth authorization URL with PKCE and role scope&quot;&quot;&quot;<br>    params = {<br>        &#39;client_id&#39;: OAUTH_CLIENT_ID,<br>        &#39;redirect_uri&#39;: REDIRECT_URI,<br>        &#39;response_type&#39;: &#39;code&#39;,<br>        &#39;state&#39;: state,  # CSRF protection<br>        &#39;code_challenge&#39;: code_challenge,<br>        &#39;code_challenge_method&#39;: &#39;S256&#39;,<br>        &#39;scope&#39;: f&#39;session:role:{ROLE}&#39;  # Role-based access control!<br>    }<br>    return f&quot;https://{ACCOUNT_HOSTNAME}/oauth/authorize?{urlencode(params)}&quot;</pre><h4>The Role Scope Pattern</h4><p>Notice the scope parameter: session:role:{ROLE}. This powerful feature binds the access token to a specific Snowflake role, enabling:</p><ul><li>Role-based MCP server access: Different users get different tools</li><li>Least privilege: Tokens are scoped to exactly what’s needed</li><li>Easy role switching: Users can re-authenticate with a different role</li></ul><h3>Role Switching in the UI</h3><p>When a user needs access to different data, they simply re-authenticate with a different role. The app can present a role selector before login:</p><pre># Role is embedded in OAuth scope<br>auth_url = get_authorization_url(https://medium.com/%3Cbr%3E%20%20%20%20state=state,%3Cbr%3E%20%20%20%20code_challenge=code_challenge,%3Cbr%3E%20%20%20%20role=role%20%20#%20Passed%20as%20session:role:{role}%3Cbr%3E)</pre><p>This ensures least-privilege access — users only see data appropriate for their current task, even if they have multiple roles granted in Snowflake.</p><h3>Step 5: Exchange Code for Token</h3><p>After the user authenticates, Snowflake redirects back to your app with an authorization code. Exchange it for an access token:</p><pre>import httpxasync def exchange_code_for_token(code: str, code_verifier: str) -&gt; str:<br>    &quot;&quot;&quot;Exchange authorization code for access token&quot;&quot;&quot;<br>    async with httpx.AsyncClient(timeout=30.0) as client:<br>        response = await client.post(<br>            f&quot;https://{ACCOUNT_HOSTNAME}/oauth/token-request&quot;,<br>            data={<br>                &#39;grant_type&#39;: &#39;authorization_code&#39;,<br>                &#39;code&#39;: code,<br>                &#39;redirect_uri&#39;: REDIRECT_URI,<br>                &#39;client_id&#39;: OAUTH_CLIENT_ID,<br>                &#39;client_secret&#39;: OAUTH_CLIENT_SECRET,<br>                &#39;code_verifier&#39;: code_verifier  # PKCE verification<br>            },<br>            headers={&#39;Content-Type&#39;: &#39;application/x-www-form-urlencoded&#39;}<br>        )<br>        <br>        if response.status_code == 200:<br>            return response.json().get(&#39;access_token&#39;)<br>        else:<br>            raise Exception(f&quot;Token exchange failed: {response.text}&quot;)</pre><h3>Step 6: Call MCP Server with OAuth Token</h3><p>Now you can make authenticated requests to your MCP server:</p><pre>async def call_mcp_tool(access_token: str, tool_name: str, arguments: dict):<br>    &quot;&quot;&quot;Call MCP tool with OAuth Bearer token&quot;&quot;&quot;<br>    mcp_url = f&quot;https://{ACCOUNT_HOSTNAME}/api/v2/databases/{DATABASE}/schemas/{SCHEMA}/mcp-servers/{MCP_SERVER_NAME}&quot;<br>    <br>    async with httpx.AsyncClient(timeout=120.0) as client:<br>        response = await client.post(<br>            mcp_url,<br>            json={<br>                &quot;jsonrpc&quot;: &quot;2.0&quot;,<br>                &quot;method&quot;: &quot;tools/call&quot;,<br>                &quot;params&quot;: {<br>                    &quot;name&quot;: tool_name,<br>                    &quot;arguments&quot;: arguments<br>                },<br>                &quot;id&quot;: 1<br>            },<br>            headers={<br>                &#39;Authorization&#39;: f&#39;Bearer {access_token}&#39;,<br>                &#39;Content-Type&#39;: &#39;application/json&#39;<br>            }<br>        )<br>        return response.json()</pre><p>The MCP server now receives requests with the user’s identity, enabling:</p><ul><li>Proper audit logging</li><li>Row-level security</li><li>User-specific context</li></ul><h3>Step 7: Put it all together — Streamlit Interface</h3><p>Here’s how to put it all together in a beautiful Streamlit app:</p><pre>import streamlit as st</pre><pre>def main():<br>    st.set_page_config(page_title=&quot;Snowflake MCP Agent&quot;, page_icon=&quot;❄️&quot;)<br>    st.markdown(&quot;## ❄️ Snowflake MCP Agent&quot;)<br>    <br>    # Handle OAuth callback<br>    if &#39;code&#39; in st.query_params:<br>        code = st.query_params[&#39;code&#39;]<br>        code_verifier = load_oauth_state(st.query_params[&#39;state&#39;])<br>        <br>        if code_verifier:<br>            access_token = asyncio.run(<br>                exchange_code_for_token(code, code_verifier)<br>            )<br>            st.session_state.access_token = access_token<br>            st.success(&quot;✅ Successfully authenticated!&quot;)<br>            st.query_params.clear()<br>            st.rerun()<br>    <br>    # Sidebar authentication<br>    with st.sidebar:<br>        if st.session_state.get(&#39;access_token&#39;):<br>            st.success(&quot;✅ Authenticated&quot;)<br>            if st.button(&quot;🔓 Logout&quot;):<br>                st.session_state.access_token = None<br>                st.rerun()<br>        else:<br>            if st.button(&quot;🔐 Login with Snowflake&quot;):<br>                code_verifier, code_challenge = generate_pkce_pair()<br>                state = secrets.token_urlsafe(32)<br>                save_oauth_state(state, code_verifier)<br>                <br>                auth_url = get_authorization_url(https://medium.com/state,%20code_challenge)<br>                st.markdown(f&#39;&lt;meta http-equiv=&quot;refresh&quot; content=&quot;0;url={auth_url}&quot;&gt;&#39;)<br>                st.stop()<br>    <br>    # Chat interface<br>    if prompt := st.chat_input(&quot;Ask about your data...&quot;):<br>        if not st.session_state.get(&#39;access_token&#39;):<br>            st.error(&quot;Please authenticate first!&quot;)<br>            return<br>        <br>        # Call MCP tools with authenticated token<br>        result = asyncio.run(call_mcp_tool(<br>            st.session_state.access_token,<br>            &quot;sales-and-marketing-analyst&quot;,<br>            {&quot;message&quot;: prompt}<br>        ))<br>        <br>        # Display results...</pre><blockquote><strong>Congratulations! You are ready with your MCP Client App</strong></blockquote><p>This approach works for Any API Integration: While this example uses Streamlit, the OAuth flow and MCP server calls are framework-agnostic.</p><h3>Further Reading</h3><h4>Role-Based Data Access Control</h4><p>One of the most powerful aspects of this architecture is how Snowflake roles control what data each user can access through the MCP server. Here’s how it works:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*p_mgrMJw51UCn5c4DtfXjg.png" /></figure><h4>The Role → Data Access Chain</h4><pre>User authenticates → Requests specific ROLE in OAuth scope → <br>Token bound to ROLE → MCP Server validates ROLE grant → <br>ROLE&#39;s privileges determine accessible tables/views</pre><h4>Different Roles, Different Data</h4><p>Consider this scenario with multiple roles accessing the same MCP server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*jKrNVv6E4N5YF_iovs3Wwg.png" /></figure><h4>Delegated User Access</h4><p>Different users can connect to different MCP servers with different roles:</p><ul><li>Sales User → Sales MCP Server (Cortex Analyst + SQL)</li><li>Finance User → Finance MCP Server (different semantic model)</li><li>Orchestrator → Routes queries to appropriate agent Framework Integration</li></ul><h4>Key Security Concepts</h4><p>1. Role Specified at Authorization Time</p><pre>scope=session:role:ANALYST_ROLE</pre><p>The role is explicitly requested in the OAuth scope. Snowflake validates that the authenticating user actually has this role granted before issuing a token.</p><p>2. Token is Bound to Role</p><p>The access token is cryptographically bound to the requested role. It cannot be used to assume a different role — the user must re-authenticate to switch roles.</p><p>3. MCP Server is Granted to Role</p><pre>GRANT USAGE ON MCP SERVER sales_mcp TO ROLE ANALYST_ROLE;</pre><p>The MCP server itself has role-based access control. Only tokens with matching roles can access the server.</p><p>4. End-to-End Identity Chain</p><pre>User Identity → Role Assignment → Token Scope → MCP Server Grant → Tool Access</pre><p>Every request carries the complete identity chain, enabling fine-grained access control and comprehensive audit trails.</p><p>The PKCE (Proof Key for Code Exchange) extension adds an extra layer of security by preventing authorization code interception attacks — particularly important for public clients like web applications.</p><h3>Conclusion</h3><p>If you have any questions, please reach out to rpalagummi@yahoo.com for further assistance.</p><h4>Resources</h4><p>🔗 Source Code: The complete implementation is available on GitHub:</p><p><a href="https://github.com/rpalagummi23/mcp_oauth_streamlit_client">⭐ github.com/rpalagummi23/mcp_oauth_streamlit_client</a></p><p>📚 Documentation:</p><ul><li><a href="https://docs.snowflake.com/en/user-guide/snowflake-cortex/cortex-agents-mcp">Snowflake MCP Server Documentation</a></li><li><a href="https://docs.snowflake.com/en/sql-reference/sql/create-mcp-server">CREATE MCP SERVER Reference</a></li><li><a href="https://docs.snowflake.com/en/user-guide/oauth-custom">Snowflake OAuth Security Integration</a></li><li><a href="https://datatracker.ietf.org/doc/html/rfc6819">OAuth 2.0 Security Best Practices (RFC 6819)</a></li><li><a href="https://datatracker.ietf.org/doc/html/rfc7636">PKCE for OAuth (RFC 7636)</a></li><li><a href="https://docs.streamlit.io/">Streamlit Documentation</a></li></ul><h4>Written by Ram Palagummi</h4><p>Sr. Solutions Engineer at Snowflake, specializing in AI/ML, Gen AI and Data Engineering. Connect on <a href="https://linkedin.com/in/rampalagummi">LinkedIn</a> or follow for more content on building secure, scalable AI applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c17d20be8a67" width="1" height="1" alt=""><hr><p><a href="https://medium.com/snowflake/connecting-to-snowflake-mcp-servers-with-oauth-2-0-and-role-based-access-control-a-complete-guide-c17d20be8a67">Build Your Own MCP Client APP — Connecting to Snowflake MCP Servers with OAuth and RBAC</a> was originally published in <a href="https://medium.com/snowflake">Snowflake Builders Blog: Data Engineers, App Developers, AI, &amp; Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>